I'm trying to free up some tokens in my game by converting some tables to strings. Here's how I am trying to convert a string back to a table (which contains tables):
stgs="102,2\102,1" for i=1,#stgs do if sub(stgs,i,i)=="," then sprite=tonum(sub(stgs,i-3,i-1)) layout=tonum(sub(stgs,i+1,i+1)) add(stg_defs,{sprite,layout}) end end |
I would expect the output for the above code to be:
{ {102,2}, {102,1} } |
However, the actual output is:
{ {102,2}, {nil,1} } |
Can anyone spot what I'm doing wrong?

1


Using \ was an unfortunate choice; it creates an escape sequence in the string and causes \102 to be interpreted as character chr(102). Choose just about anything else instead and it should work!



Haha, I knew it would be something stupid! Thanks for spotting the mistake.
[Please log in to post a comment]