Jump to content

Need help with two-dimensional tables


DiSaMe

Recommended Posts

Posted

When I do something like

local sometable = {{}} 

then I can't do anything like

sometable[2][2] = true 

. I get an error: attempt to index field '?' (a nil value). But if I define table in this way:

local sometable = 
{ 
    {false,false} 
    {false,false} 
} 

, then it's ok. But I need 32x32 table and I'm not going to copy & paste that much words. How to define table like that?

Posted

Looping is your friend.

  
myTbl = {}; 
  
for x=1,32 do 
    myTbl[x] = {}; 
     
    for y=1,32 do 
        myTbl[x][y] = false; 
    end 
     
end 
  
  

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...