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

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.

Well,

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

1
2
3
4
5
6
7
8
9
10
11
12
13
--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

Yep robmiracle, I was missing the second declaration :)

Joakim

views:1708 update:2012/2/9 11:37:26
corona forums © 2003-2011