proc/text2list(var/text = "" as text)
var/length = length(text)
if(length > 0)
var/list/charlist = list()
var/charlistnum = 1 as num
var/char = "" as text
while(length)
char = copytext(text,1,2)
charlist[charlistnum] = char
charlistnum += 1
text = copytext(text,2,0)
length -= 1
return charlist
else return list()
This proc is supposed to return a list of each piece of the text string inputed. So, I set up a test:
mob/verb/test()
var/test = text2list("test")
world << "test[1] == [test[1]]\nIt should be == t"
However, I get a runtime error when I run test() that looks like the following:
runtime error: list index out of bounds
proc name: text2list (/proc/text2list)
usr: Lord of Water (/mob)
src: null
call stack:
text2list("test")
Lord of Water (/mob): test()
runtime error: cannot read from list
proc name: test (/mob/verb/test)
usr: Lord of Water (/mob)
src: Lord of Water (/mob)
call stack:
Lord of Water (/mob): test()
Can you help me figure out how to eliminate this error?
Try the TextHandling library, which handles this for you with the dd_text2list() function.
byond://Deadron.TextHandling