I need a way to insert new keys (in my case, new tables) into a pre-existing table.
table.insert() only seems to insert values.
local level = {}
table.insert(level, block = {})
Obviously that doesn't work.
Thanks!
Dane
![]() |
|
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
I need a way to insert new keys (in my case, new tables) into a pre-existing table.
table.insert() only seems to insert values.
local level = {}
table.insert(level, block = {})
Obviously that doesn't work.
Thanks!
Dane
hi how u doin? im just browsing now for table answers, almost like arrays but have few unique features which has got me confused. Try this link:
Let me know if its helped I think it has the answer. Got me started but im still stuck on getting my head around what is happening with this example:
1 2 3 4 5 6 7 8 | bombDropTimes = {} local interval = 1 / bombsThisLevel for i = interval, 1, interval do local dropTime = math.round(math.sin(i * (math.pi / 2)) * levelDuration) print(dropTime) bombDropTimes[#bombDropTimes + 1] = dropTime end |
Ok I got mine to work:
local stash = {}
stash.bullets = 5
--I just had so many tables within tables I missed declaring one of them.
For your question,
Yeah it looks like it checks the first entry in the table. If it matches, then the first entry in the table is removed (line 6) and a bomb is dropped. So each time there is a different first entry.
table.remove() will remove the last entry unless you specify a position, like was done here.
Dane
Thanks for the answer, makes perfect sense now. Used to using push.array() and shift.array() etc with javascript.
I like being able to store functions in them.