Could you describe why we need to include fighting like this:
monsterHealth = monsters[fighting].health;
I know we have a variable named monsters that have health but why we add [fighting] to the code? what does it do?
Know that I have set fighting with different numbers so far but they are at the bottom of the page
function fightSlime() {
fighting = 0;
goFight();
};
function fightBeast() {
fighting = 1;
goFight();
};
function fightDragon() {
fighting = 2;
goFight();
};
When one of the functions to fight a monster is called, the fightingvariable is assigned. Each monster has a fighting number, which corresponds to the index of the monsters array.
For example calling fightSlime sets fighting to 0.
Then, the goFight function is called, where the monsterHealth variable is assigned.
So, now the code has access to information about what monster the player is fighting, and then setting the health of just that monster.