Search found 5 matches
- Mon Aug 19, 2024 12:05 am
- Forum: Support and Development
- Topic: Calling draw/update functions from a table in for loop?
- Replies: 10
- Views: 10263
Re: Calling draw/update functions from a table in for loop?
Your problem could be caused by all enemies referencing the same object. This looks suspicious: local spawndEnem = self.enemList['enemy1'] table.insert(self.activeEnemies, spawndEnem) Note that the first assignment does not make a copy of the enemy1 table: it "points" to the table. So, th...
- Fri Aug 16, 2024 10:51 pm
- Forum: Support and Development
- Topic: Calling draw/update functions from a table in for loop?
- Replies: 10
- Views: 10263
Re: Calling draw/update functions from a table in for loop?
The best part of Lua: pairs for index, activeEnemy in pairs (self.activeEnemies) do activeEnemy:draw() end It iterates all and each element in the table "self.activeEnemies", even not numerical indices. But the ordering will surprise you. The second best part of Lua is ipairs : for index,...
- Thu Aug 15, 2024 6:31 pm
- Forum: Support and Development
- Topic: Calling draw/update functions from a table in for loop?
- Replies: 10
- Views: 10263
- Thu Aug 15, 2024 5:30 pm
- Forum: Support and Development
- Topic: Calling draw/update functions from a table in for loop?
- Replies: 10
- Views: 10263
Re: Calling draw/update functions from a table in for loop?
Hi and welcome to the forums. That snippet looks right, so the issue is probably elsewhere. Can't really help with just that much. The only other snippets that i think could contribute to the issue is: if Mouse:key_down(1) then local spawndEnem = self.enemList[1] table.insert(self.activeEnemies, sp...
- Thu Aug 15, 2024 6:28 am
- Forum: Support and Development
- Topic: Calling draw/update functions from a table in for loop?
- Replies: 10
- Views: 10263
Calling draw/update functions from a table in for loop?
I'm trying to make a table that will have enemies inserted/removed as you're playing, but they all have their own draw and update function, my current code only triggers on the last added table entry but i need them all to be active. Any suggestions? for i = 1, #self.activeEnemies, 1 do self.activeE...