while (true) {
var enemy = hero.findNearestEnemy();
// With AND, the type is only checked if enemy exists.
if (enemy && enemy.type == "munchkin") {
hero.attack(enemy);
}
// Find the nearest item.
let item = hero.findNearestItem();
let pos = item.pos;
let posX = pos.x;
let posY = pos.y;
// Collect item if it exists and its type is "coin".
if(item && item.type == "coin"){
hero.moveXY(posX, posY);
}
}
@milton.jinich no thats not the reason. Its because I joined a class do you see the back to classroom button. But I am emailing the support right now to unlink my account from the classroom
while (true) {
var item = hero.findNearestItem();
var distance = hero.distanceTo(item);
// If the item's type is "gem"
// OR the distance to the item less than 20 meters:
let pos = item.pos;
let x = pos.x;
let y = pos.y;
if(item.type == "gem" || distance < 20){
// Move to item's position.
hero.moveXY(x, y);
}
}
It might take them a while to respond to the email because they work on monday to friday.
But this is getting off topic so its fine i will figure it out later
You must almost copy the code given in the default code:
while (true) {
let enemy = hero.findNearestEnemy();
// With AND, the type is only checked if enemy exists.
if (enemy && enemy.type == "munchkin") {
hero.attack(enemy);
}
// Find the nearest item.
let item = hero.findNearestItem();
// Collect item if it exists and its type is "coin".
if (item && item.type == "coin")
// put here your code for moving to the item
// use moveXY or move() if you have more advanced boots
}
But the most important lesson from this code is that @Deadpool198, @jka2706 and so on…
We can use now let and probably other a little bit more advanced features of java script without superfluous and annoying warnings and false errors