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

Hello guys!
When I use this ability my hero just gets bigger and does nothing.
Is it right behavior for this spell (hero.powerUp)?
I don’t understand what’s the point?

Video

Code:

function attackEnemy(enemy) {
    if (enemy && enemy.health > 0) {
        if (hero.isReady("jump") && hero.distanceTo(enemy) > 5) {
            hero.jumpTo(enemy);
        } else if (hero.isReady("punch")) {
            hero.punch(enemy);
        } else if (!hero.hasEffect("power-up") && hero.isReady("power-up")) {
            console.log('HeroDebug', hero.isReady("power-up"));
            console.log('HeroAttackDamage', hero.attackDamage);
            hero.powerUp();
            hero.attack(enemy);
            console.log('HeroAttackDamage', hero.attackDamage);
        } else if (enemy && enemy.health > 0) {
            hero.attack(enemy);
        }
    }
}
let isFirstChallengeComplete = false;
let firstPoint = {
    x: 115,
    y: 24
};
while (!isFirstChallengeComplete) {
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.distanceTo(enemy) < 50) {
        attackEnemy(enemy);
    } else {
        if (hero.pos.x === firstPoint.x && hero.pos.y === firstPoint.y) {
            isFirstChallengeComplete = true;
        } else {
            hero.move(firstPoint);
        }
    }
}
hero.say("End of the program!");

1 Like

I get this bug too. This probably isn’t a server bug.

Welcome to the forum @Geralld! We hope you enjoy your time here :slight_smile:

Before you continue, make sure to check out our rules and guidelines to get a feel for everything about this discourse!

Also great job formatting your code!

:wolf:
-@Luke10

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

Welcome to the CoCo Discourse, @Geralld! Here, you can ask for Level Help(though don’t ask for complete answers), report bugs(just like this one), paste Baby Yoda memes, and more! Make sure to review this topic :smile:

Rachel

Thanks for the clarification! Now it works, BUT…
the result much worse than without powerUp ability :open_mouth: :roll_eyes:
I’m a little confused: in what case would the use of this skill be useful?
If the hero is surrounded by many enemies to reduce the damage taken?

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 {
            hero.attack(enemy);
        }
    }
}

@Chaboi_3000 has explained this. It is very good and midhealth swarms (chabois post here Sword powerUp() ability question - #8 by Chaboi_3000 and on Sword powerUp() ability question - #10 by Chaboi_3000)
thats almost 50% better, making it very usefull. Just dont use it against warlocks :grinning_face_with_smiling_eyes:

1 Like