[JavaScript] Strange behavior for hero.powerUp() - Sword of the Temple Guard (The Trials level)

There was a topic Sword powerUp() ability question with the original name
Sword powerUp() ability compromized
The proper use of it is:

      if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
            hero.powerUp();
      else hero.attack(enemy);  // test without else - I think you will receive more damage

I think your code doesn’t work because hero.punch(enemy) and hero.powerUp() don’t work when used one after the other. So the function will be:

function attackEnemy(enemy) {
    if (enemy && enemy.health > 0) {
        if (hero.isReady("jump") && hero.distanceTo(enemy) > 5) 
            hero.jumpTo(enemy);
        else if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
                      hero.powerUp();
        else if (enemy && enemy.health > 0)
            hero.attack(enemy);
        }
}

You’ll complete the level a bit quicker without the powerUp , the damage you’ll receive is a toss and situational.
Tested first PoweUp and then Punch, it works somehow

function attackEnemy(enemy) {
    if (enemy && enemy.health > 0) {
        if (hero.isReady("jump") && hero.distanceTo(enemy) > 5) 
            hero.jumpTo(enemy);
        else if (!hero.hasEffect("power-up") && hero.isReady("power-up"))
                      hero.powerUp();            
        else if (hero.isReady("punch"))
            hero.punch(enemy);    
        else if (enemy && enemy.health > 0)
            hero.attack(enemy);
        }
}

but the hero dies.
I’m curious if we replace Punch with Chain Lightning but didn’t test it

2 Likes