Log In  

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?

P#78740 2020-07-01 05:32 ( Edited 2020-07-01 05:33)

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!

P#78743 2020-07-01 06:41 ( Edited 2020-07-01 06:42)

Haha, I knew it would be something stupid! Thanks for spotting the mistake.

P#78744 2020-07-01 06:44

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 11:25:59 | 0.006s | Q:9