- Edited
I'm trying to build a simple turn based battle system. To handle turn order, i'm putting enemies into an array, and letting them take turns. When an enemy is done with its turn, it gets popped from the array and the next enemy acts.
However, if an enemy is killed and freed from the array, it still remains as a <Freed Object>, so the array is not truly empty. This can mess up checks for whether enemy_array.is_empty() for example.
I've been using a work_around like this to check if my enemy_array is empty, so the player's turn can start when all enemies have acted:
if !enemy_turn_order.is_empty() and enemy_turn_order[0] != null:
enemy_turn_order.pop_front().take_turn()
My main question would be, does a freed object count as null? Should i just treat it as such to avoid errors/bugs?
Also if anyone has better advice for how to handle turn order in general, i'm all ears. I've been at this mini project for a month, but i can't seem to find a good solution for handling multiple enemies. Single enemy is no problem, but multiple actors taking turns becomes confusing fast.
edit:
Seems making the enemy remove itself from the array on death seems to be an option to avoid the Freed Object clogging up the turn order:
enemy_turn_order.erase(self)