inserting keys into table

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 [import]uid: 117490 topic_id: 21039 reply_id: 321039[/import]

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:

http://community.codemasters.com/forum/operation-flashpoint-dragon-rising-mission-editing-modding-chat-zone-123/394286-lua-tutorial-fun-tables.html

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:

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  

Later used like this:

function checkForBombDrop()  
 if #bombDropTimes == 0 then  
 return  
 end  
 if frameCounter == bombDropTimes[1] then  
 table.remove(bombDropTimes, 1)  
 dropBomb()  
 end  
 end  

For me its working but I dont understand how the table is being looped, I understand the dropBomb() triggering but not what its looking into e.g. its always checking == bombDropTimes[1]???

Sorry for hi jacking, just having table misunderstanding myself.

All help to uncover the mysteries welcome. :slight_smile: [import]uid: 118379 topic_id: 21039 reply_id: 83138[/import]

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 [import]uid: 117490 topic_id: 21039 reply_id: 83144[/import]

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. [import]uid: 118379 topic_id: 21039 reply_id: 83315[/import]