I have a game where zombies spawn every 2 seconds.
Each Zombie instance has:
-
a timer property that is used for their AI.
-
a deleteMe function that kills the zombie, and removes all of its properties
- other functions such as attack(), run()… blah blah blah… (you get the point)
Whenever an instance of a Zombie is created, i add it to a TableOfZombies.
My help is this:
Q1 How can i remove a particular Zombie from the table when it is shot dead by the player?
Q2 How can i pause the timer of all the on-screen Zombies when the game is paused?
Q3 (similar to Q2) How can i kill all the Zombies when the game is over?
Heres how i spawn my zombies
function spawnZombie() table.insert(TableOfZombies, newEnemy(math.random(0,4), math.random(1,3), MainCharacter, SpawnLocation[math.random(0,7)], math.random())) GameActionLayer:insert(TableOfZombies[#TableOfZombies]) timer.resume(TableOfZombies[#TableOfZombies].timer) TableOfZombies[#TableOfZombies].Index = ZombieIndex + 1 end
Heres how i delete a particular Zombie when it’s shot
table.remove(TableOfZombies,ThisEnemy.Index)
Heres how i try to pause their time , but i keep getting an error saying: attempt to index a nil value
for Kount = 1, #TableOfZombies, 1 do if(TableOfZombies[Kount] ~= nil) then timer.pause(TableOfZombies[Kount].timer) end end
Any help will greatly be appriciated… thanks