[SOLVED] Gas Attack Help (JS) - Sarven Desert

Ummmm. The enemyIndex? I still don’t understand whats wrong with that part of the code.

‘enemyIndex’ is your counter. It keeps track of where you are at in the list of ‘enemies’. ‘enemies’ is the array that contains that list.

Every time the code loops through, enemyIndex is incremented. This equates to:

At the start: enemyIndex = 0 --> enemies[enemyIndex] --> enemies[0]
Next loop enemyIndex = 1 --> enemies[enemyIndex] --> enemies[1] 
etc

This is counting through your list of enemies. You need to use your counter to specify which enemy you are working with.

1 Like

That’s my question. I don’t know how to specify the enemy that I am trying to defeat.

Instead of:

use:
totalHealth += enemies[enemyIndex].health

‘enemies’ is your list of all the enemy troops; ‘enemyIndex’ is your counter…since the counter increments by 1 on every loop completed, this cycles (iterates) through the list of enemies.

3 Likes

Thank you so much!!! :star_struck:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.