Hello, hopefully I've posted this in the correct area, the BBS is a little confusing.
The three lines below are really troubling me.
The first one demonstrates that we have access to i, x, and y.
The second one demonstrates that we have access to a[1][1][1].
The third one should evaluate to a[1][1][1] which we have access to and stores the value "0", but instead it crashes.
The code:
print(i..x..y) -- returns "111" print(a[1][1][1]) -- returns "0" which is the correct value stored there print(a[i][x][y]) -- error |
The error:
print(a[i][x][y]) -- error attempt to index field "?" (a nil value) |
Does anyone know why it works this way? Any advice on the correct syntax? I can post the full code if needed, but it's somewhat obfuscated in favor of fewer characters.
Thanks for reading!
Thanks for the replies, both of you. I think I figured it out based on what cakepie said. Looking at my code, I'm using sub() to load "x" and "y", drawing from a string, so even though I'm drawing numbers, they're probably being handled as a string. I'll try a different implementation of that part, and I'll post back here if I either have any more trouble or land on a specific implementation that's simple and relevant enough to share. Might be as simple as removing quotations or casting to another type, I'm fairly new to Lua obviously, but I'd imagine I can figure out something.
Here's the full code for anyone curious, sorry for the delay. I'm sure it looks really weird, haha. I'm generating an array to store tetrominoes, which I'll reference later. The strings contain information about which spaces need to be filled for each of the tetrominoes, with every 4 characters in "s" describing the 4 places blocks can go in a shape, and every two characters in "c" acting as coordinates describing where to place each numerical block in a 2d array, which itself is stored in an array, indexing each possible shape a tetromino can be.
The print() calls in the OP were just for debugging purposes.
s="1358468935895689678956795690" c="11211222132333142434" a={} for i=1,7 do a[i]={} for j=1,3 do a[i][j]={} for k=1,4 do a[i][j][k]=0 end end for l=1,28 do d=sub(s,l,l) x=sub(c,d,d) y=sub(c,d+1,d+1) print(i..x..y) -- "111" print(a[1][1][1]) -- "0" print(a[i][x][y]) -- error a[i][x][y]=1 d+=2 end end |
[Please log in to post a comment]