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);
}*/
}
}
}
}
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.
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 button do? I’ve never had a student account so I’ve not seen this before.
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.
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.
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).
@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);
}*/
//}
}
}