Lua table expert out here?

Hi, this must be a simple one - but I can’t find any documentation about this…I guess there are, but sometimes it is sooo hard to search the net…

So this is what I want to do:

local levelAssets = {}
levelAssets[1].name = event.other.lhUniqueName
levelAssets[1].objtype = “COIN”

But that is not the right approach…I tried table.insert but that didn’t give me any success either…

Best regards, Joakim

[import]uid: 81188 topic_id: 20966 reply_id: 320966[/import]

Try

local levelAssets = {}
levelAssets[i] = {}
levelAssets[1].name = event.other.lhUniqueName
levelAssets[1].objtype = “COIN”

The first one creates a table called levelAssets, the levelAssets[1] = {} creates a table in that cell.

[import]uid: 19626 topic_id: 20966 reply_id: 82784[/import]

Well,

I’m no expert myself but when I do business apps I have an external file with variables etc

--myVars.lua  
  
local myVar = {}  
  
myVar.CLIENT\_NAME = "Bob Bobster"  
myVar.CLIENT\_PHONE = "1234567890"  
myVar.FB\_APP\_ID = 1234567890  
myVar.TWITTER\_APP\_ID = 1234567890  
myVar.THE\_TEXT\_COLOR = 123, 123, 33, 255  
myVar.FONT\_NAME = "Arial"  
myVar.FONT\_SIZE = 14   
  
return myVar  
  

Then when I need something I just call it like this:

require("myVar")  
  
local text = display.newText(myVar.CLIENT\_NAME, 100, 100, myVar.FONT\_NAME, myVar.FONT\_SIZE)  
text:setTextColor(myVar.THE\_TEXT\_COLOR)  

I guess you could do something like this with games too, there’s probably better ways of doing this but it works for me. [import]uid: 13560 topic_id: 20966 reply_id: 82787[/import]

Yep robmiracle, I was missing the second declaration :slight_smile:

Joakim [import]uid: 81188 topic_id: 20966 reply_id: 82801[/import]