I don't know if this is a bug or feature, but it seems to me that nested loops do not work.
I attempted to use the following code, debugging the text showed that only one loop occurred:
local x=0 local y=0 while(x<16) do while(y<16) do val=mget(x,y) print(val) y+=1 end x+=1 end |
I don't know if this is intended or a limit of lua, but I was able to work around it with the following code:
local i=0 while(i<256) do local x=i%16 local y=(i-x)/16 val=mget(x,y) print(val) i+=1 end |



There's a small bug in the first example -- y is not reset to 0 in the outer loop, and so the second time the inner loop is reached, (y < 16) is already false. Should be:
local x=0 local y=0 while(x<16) do y=0 while(y<16) do val=mget(x,y) print(val) y+=1 end x+=1 end |
And for anyone new to Lua reading this, the same code could be alternatively expressed with for loops:
for y=0,15 do for x=0,15 do val=mget(x,y) print(val) end end |
[Please log in to post a comment]