[Solved] Mad Maxer Strikes Back - Always dying

My charachter always gets killed in Mad Maxer Strikes Back …

seems to be a bug

// The smaller ogres here do more damage!
// Attack the ogres with the least health first.
while (true) {
    var weakest = null;
    var leastHealth = 99999;
    var enemyIndex = 0;
    var enemies = hero.findEnemies();
    // Loop through all enemies.
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        // If an enemy's health is less than leastHealth,
        if (enemy.health < leastHealth) {
            // make it the weakest and set leastHealth to its health.
            weakest = enemy;
            leastHealth = weakest.health;
        }
        //  Don't forget to increase enemyIndex by 1.
        enemyIndex++;
        if (weakest) {
            // Attack the weakest ogre.
            while (weakest.health > 0) {
                hero.attack(weakest);
                /*if (hero.isReady("cleave") && hero.distanceTo(weakest) < 10) {
                    hero.cleave(weakest);
                }*/
            }
        }
    }
}

How much health do you have. What is your equipment

1 Like

I have read things of equipement but I do not know where to get any of it O_o i’ts a student account. Maybe it’s a bad setup?

my health is 851.

I have encountered many similar problems before. I was able to get around them.

Try changing leastHealth = weakest.health; to leastHealth = enemy.health;

Also, since cleave has a cooldown, I usually put it first to prioritize it before attack.

1 Like

I tried that, but since weakest = enemy it doesn’t matter. Also cleave makes no sense with the cool down that’s why i block-commented it. (I tried it first and after attack, made no difference)

My character attacks and does what it is supposed to, but dies before waves are over. I believe the code to be correct.

I just ran your code in JS and it worked fine. I used up 649 health. Which hero are you using and please take a screen shot of your equipment. Thanks.

1 Like

Anya, my character has 851 health and I have no equipement, I also do not know where I would get equipement.

Click on the game menu in the middle. That sword is way too slow.

1 Like

I get options there.

You’re missing the “change hero” tab which should be right above the “options” tab. It’s not there because you’re using a student account. What does this Button02 button do? I’ve never had a student account so I’ve not seen this before.

1 Like

It beautifies the code.

So uhm what am I supposed to do? I contacted them via Facebook, got no reply. Who has to fix it?

I can change the hero in the course selection menu, yet they all have 851 health.

Also my account has NO access to the standard platform at all.

1 Like

if you have a student account, then there must be a teacher. Have your teacher contact team@codecombat.com and let them know that your code works for others with different equipment, but you as a student cannot complete it with your current equipment.

1 Like

okay… will take days until teacher replies probably. They use it as a learning platform for a pre-registration test. So I technically am not even a student yet O.o.

@MunkeyShynes students can’t choose their equipment. They can only choose heroes (which all have the same stats) and they are required to use the given equipment and beat the level

@Chaboi_3000 this doesn’t help me if my code seems fine, or what am i missing? I am on it for days now. And people who were able to change/upgade their gear can do the level with my code.

I knew that. I asked about the equipment before he said it was a student account. After he said it, I was curious what equipment he was using because the code was working for me and the equipment that I was using.

This part:

        if (weakest) {
            // Attack the weakest ogre.
            while (weakest.health > 0) {
                hero.attack(weakest);
                /*if (hero.isReady("cleave") && hero.distanceTo(weakest) < 10) {
                    hero.cleave(weakest);
                }*/
            }
        }

… should be after the while (enemyIndex < enemies.length) { /* stuff */ } loop, not inside it. What this is doing is attacking the weakest ogre that you have seen each time you look at an ogre to see how weak it is. Instead, you want to look at all the ogres to find the weakest (finishing that loop), then attack the weakest one (starting your if(weakest) { /* attack */ } at the same level as that loop (indented 4 spaces).

2 Likes

i did that before and it resulted in the same.

@nick ok i muisunderstood what you were saying, well i get an error on line 12

// The smaller ogres here do more damage!
// Attack the ogres with the least health first.
while (true) {
    var weakest = null;
    var leastHealth = 99999;
    var enemyIndex = 0;
    var enemies = hero.findEnemies();
    // Loop through all enemies.
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        // If an enemy's health is less than leastHealth,
        if (enemy.health < leastHealth) {
            // make it the weakest and set leastHealth to its health.
            weakest = enemy;
            leastHealth = weakest.health;
        }
    }
        //  Don't forget to increase enemyIndex by 1.
        enemyIndex++;
        if (weakest) {
            // Attack the weakest ogre.
            //while (weakest.health > 0) {
                hero.attack(weakest);
                /*if (hero.isReady("cleave") && hero.distanceTo(weakest) < 10) {
                    hero.cleave(weakest);
                }*/
            //}
        }
}

@Peter_Alfons_Loch you put the enemyIndex++ out of the while loop so it kept going on forever.