Im on CS3 on the Forest shadow level, I have tried doing all the ways I could but my code just does not do what it needs to.
while (true) {
// Find the nearest enemy.
var enemy = hero.findNearestEnemy();
// Attack it only if its type is "thrower" or "munchkin".
if (enemy.type == "thrower" || "munchkin") {
hero.attack(enemy);
// Find the nearest item.
var item = hero.findNearestItem();
if (item) {
// Collect it only if its type is "gem" or "coin".
if (item.type == "gem" || "coin") {
hero.moveXY(item.pos.x, item.pos.y);
}
}
}
}
Despite the enemy.type it keeps attacking the ogres and brawlers, without killing munchkins or throwers first. Javascript language, no errors shown in code
var item = hero.findNearestItem();
if (item) {
// Collect it only if its type is "gem" or "coin".
if (item.type == "gem" || "coin") {
hero.moveXY(item.pos.x, item.pos.y);
the solution didnt work, but i figured it out because apparently enemy.type is needed for both or
this was the solution i had
while(true) {
// Find the nearest enemy.
var enemy = hero.findNearestEnemy();
// Attack it only if its type is "thrower" or "munchkin".
if (enemy.type == "munchkin" || enemy.type == "thrower") {
hero.attack(enemy);
}
// Find the nearest item.
else {
var item = hero.findNearestItem();
if (item) {
if (item.type == "gem" || item.type == "coin") {
hero.moveXY(item.pos.x, item.pos.y);
}
}
}
}
// Collect it only if its type is "gem" or "coin".