ID:139001
 
Code:
mob
var/MHP = 100
var/HP = 100
Login()
..()
UpdateHealth()
proc
UpdateHealth()
var/objx = 20
var/objy = 20
for(var/L in "Health: [HP]")
var/obj/font_letter/f = new
world << f
f.icon_state = "[L]"
f.screen_loc = "[objx],[objy]"
world << f.icon_state
world << f
client.screen+=f
objx++



obj
font_letter
icon = 'Arial7pt.dmi'


Problem description:
Basically, i am trying to create a loop with a string. What i am trying is to try to get the variable L to = each letter in that string and assign it to a new font_letter and change it icon_state to the correct letter.
I recieve no errors but it doesnt appear.
Unless you've got a 20x20 screen, I don't think that it's going to pop up.
In response to Lugia319
What size is my screen then?
In response to PCGeek
By default it's 15x15 IIRC. (world.view = 7)

EDIT: I'd also like to note that if the map is like 10x10, you will see the whole thing
In response to Lugia319
I changed the position but it still doesnt show up.
In response to PCGeek
Okay, I looked it up at the view is actually 11x11 default. Sorry (world.view = 5)
In response to Lugia319
Still doesnt show.
In response to PCGeek
<s>Also, I wanted to note that your code is going to stack all of the letters on top of each other. </s> Nevermind. Didn't see last line. But it does make it so that you have 1 letter per tile
In response to Lugia319
Where do i put that extactly?

When i put the letter on the screen?

[Edit]

tried it doesnt work.
In response to PCGeek
Found it. Your for() loop isn't working. Try using copytext instead.
In response to Lugia319
Can i have an example for that please?
In response to PCGeek
Copytext returns a text string. Since you to do this proc for each letter, I'd suggest doing something like this.

1. Define the length of the text string
2. Define a generic variable to be 0
3. Copytext (and add) each letter individually

var/X = copytext("Hello", X, X + 1)

This will return the letter you want it to return

Note: Make sure you add 1 to that generic variable each time so that you progress through the text string.
In response to Lugia319
And what if i have a variable in it/ Would it still right? And im unsure how to do the loop for it.
In response to PCGeek
A variable is fine.

var/X = copytext("[src.Hp]",1,2)


Works just as well as anything else.

As for the loop, you could have a while(X < textlength) (X being the number of the letter you are copying)
In response to Lugia319
You can use the length() proc to get the length of the string.

To loop through every character in a string I'd do the following:

var/string = "Some string with stuff"
var/char
for (var/i = 1, i <= length(string), ++i)
char = copytext(string, i, i + 1)
world << "character [i] is [char]"


EDIT: Better yet, make a variable to store the length

var/string = "Some string with stuff"
var/stringlen = length(string)
var/char
for (var/i = 1, i <= stringlen, ++i)
char = copytext(string, i, i + 1)
world << "character [i] is [char]"
In response to Lugia319
Lugia319 wrote:
Unless you've got a 20x20 screen, I don't think that it's going to pop up.

I should mention that screen objects will still show up, even if they are outside of the viewing screen. Read the last 2 paragraphs of this.
In response to Complex Robot
Complexrobot example helped a lot. Now i gotta space them out correctly... Any tips on how to do this?
In response to PCGeek
Instead of using tiles, use pixel location.
In response to Lugia319
Can i have an example of pixel location just to make it clearer?
In response to PCGeek
obj
Letter
pixel_x = 10
pixel_y = 10


If you created a new letter, it would appear 10 pixels to the right and 10 pixels from the bottom.
Page: 1 2