ID:139871
 
Code:
proc
TextToList(var/t2l)
var/list/text1[length(t2l)]
var/i=1
for(i=1,i<=length(t2l),i++)
usr << i
var/text = copytext(t2l,i,i+1)
text1 += list(i=text)
return text1


Problem description:

I am trying to make a proc that turns an string into a list of individual letters. The code compiles perfectly fine, but when I try to view the list it gives me ONE single item on the list which is "i" instead of the individual numerical numbers. The variable I is changing perfectly fine, but for some reason when adding to the list it will not take the value of 'i' it takes the name of the var and puts it into the list (4 times in the example below.)

What the code should do:
1) Take the string
2) Make a list of each individual letter
3) Return that to the calling proc/verb.

What the list should be (when t2l = "Test")
list(1="T",2="e",3="s",4="t")

OR
list(0="T",1="e",2="s",3="t")


What seems to be the actual result (when t2l = "Test")
list("i"="T","i"="e","i"="s","i"="t")


Any help with my conundrum will be very appreciated (especially if a better way then "copytext" for this.)

(Also please not its been forever since I have programmed in byond, I've been working in java for a while so I'm pretty rusty at this. :P)
try using "[i]" when appending it to the list. it might make a difference since it's in text format instead of numerical format. I'm not sure on this though. I suck with lists.
An associative list won't work here as you are attempting to index with numerical values. Of course, this doesn't matter, because you are attempting to index with numerical values and so you can just use a normal list.

Just initialize the list using list() and add each letter one at a time.
In response to Garthor
Without an associative list, if there are two of the same letters it wont show up though only 1 of them shows :S
In response to Bravo1
Thankyou very much this actually worked XD

wonder why it doesnt work just as an integer though =/
In response to KingCold999
Lists are lists, not sets. They can contain duplicate entries.

Well, associative lists can't have duplicate keys, but you very much don't need one here.
In response to KingCold999
Because X[5] is defined to be the 5th element of a list. This supercedes associative indexing, and so if you attempt to use 5 as a key, X[5] will still just give you the fifth element of the list.