1
I'd probably do it like this, though I'm sure there are more efficient ways:
screen={} for x = 1,18 do add(screen,{}) for y = 1,18 do add(screen[x],1) end end |
1
@2bitchuck
I just checked. It's more efficient to use the index directly when you know what it is, rather than using add
. I suspect it's because add
requires a length lookup, which gets slightly slower for each item already in the table with an integer index.
As such, this version is faster, though yours is probably better for beginners due to readability.
screen = {} for x = 1,18 do screen[x] = {} for y = 1,18 do screen[x][y] = 1 end end |
[Please log in to post a comment]