In a tower defense game, I want to check each enemy, see if they are within range of bullets, then for each bullet in range, see if the bullet has already touched the enemy. Using Array Tools extension.
I am using object groups: Enemies and Tower_Bullets
I want to use Enemies.array_bullet_IDs_touched to store the Tower_Bullets.ID of each bullet touched.
For each Enemies, for each Tower_Bullets in range
- if Enemies array is empty, then add bullet ID to array (this seems to work as intended).
- if Enemies array is NOT empty,
2a. if array contains the bullet ID, then do not add the ID again (do nothing)
2b. else if array does NOT contain the bullet ID, then add bullet ID to array
What’s working
The #1 event works as intended: the very first bullet to hit an enemy, the ID is added to the enemy array.
What’s not working
The problem is within #2 event: Subsequent bullets hitting the enemy always register as having already hit the enemy, thus the ID’s are not added to the enemy array. In the console logs, I expected to see another instance of the highlighted log for the subsequent bullets at the point of the red arrow. Do you see something I’ve overlooked? Or have you had any issues using the Array Tools number checks or know of a better solution? Thanks!