ID:154955
 
proc
Apply_Text(msg,x,y)
world << "[msg]"
for(var/i = 1, i < 10, i++)
if(findtext(msg, "a", i, i+1))
var/obj/letter/L = new/obj/letter/a
L.loc = locate(x + i, y)
if(findtext(msg, "b", i, i+1))
var/obj/letter/L = new/obj/letter/b
L.loc = locate(x + i, y)
if(findtext(msg, "c", i, i+1))
var/obj/letter/L = new/obj/letter/c
L.loc = locate(x + i, y)


obj
letter
icon = 'letters.dmi'
a
icon_state = "a"
b
icon_state = "b"
c
icon_state = "c"

mob
Login()
..()
Apply_Text("bac",x,y)


Clearly I have no idea what I'm doing? O_o
If you don't know what we're trying to do, we don't either, and can't help you.

From what I am looking at it seems you are wanting to create an object everytime you find one of the letters?

for(var/i = 1, i < 10, i ++ )


On <code>i < 10</code> you should be be using the length of the string. <code>i <= length(text)</code>.

Preferably using <code>copytext()</code>, this is how I would approach this.

var { start = 0 ; end = 1 ; current_letter = null }

for( var/pos, pos <= length( string ), pos ++ ) { letter = copytext( string , ++ start , ++ end ) ; world << "Current letter: [current_letter]" }


<code>start</code> would obviously be the starting position of the text and <code>end</code> would be the position after the starting point.

You are creating objects in a non-pretty manner.

var/obj/letter/L = new/obj/letter/a

L.loc = locate(x + i , y )


This could be done more easily doing <code>new/obj/letter/a(locate(x + a number, y , z))</code>.
In response to Neimo
Neimo wrote:
if(findtext(msg, "a", i, i+1))

This would add on to <code>i</code>, messing up the count and skipping positions.


This is wrong. <code>i+=1</code> would add on to <code>i</code>, but <code>i+1</code> will simply result in what was expected.
In response to El Wookie
Thanks for acknowledging that error. I guess when I was testing I did not catch on to that, though I was using <code>++i/++pos</code> and it was skipping around.
In response to Neimo
The more you know ;)
In response to El Wookie
Yep, thanks guys.

I felt the code was self explanatory, and I didn't have much time. :p