I've been using CodeCombat for learning. With this code here I've been stuck for a week and nobody can help me. I'm trying to understand why the Y-coordinate property (particularly hero.pos.y) isn't updating. It doesn't register as changed although my hero moves to the position x:18 y:24. Everyone who's willing to help is welcome to reply.
hero.moveXY(18, 40);
while (true) {
hero.say("starting while");
var enemy = hero.findNearestEnemy();
var friend = hero.findNearestFriend();
var item = hero.findNearestItem();
if (enemy) {
if (enemy.type == "ogre" && hero.canCast("force-bolt")) {
hero.cast("force-bolt", enemy);
} else if (enemy.type == "brawler" && hero.canCast("shrink")) {
hero.cast("shrink", enemy);
hero.moveXY(34, 24);
} else if (enemy.type == "scout" && hero.canCast("poison-cloud")) {
hero.cast("poison-cloud", enemy);
hero.moveXY(50, 24);
}
} else if (friend) {
if (friend.type == "soldier" && hero.canCast("heal")) {
hero.cast("heal", friend);
} else if (friend.type == "goliath" && hero.canCast("grow")) {
hero.cast("grow", friend);
} else if (friend.type == "paladin" && hero.canCast("regen")) {
hero.cast("regen", friend);
}
} else if (item) {
if (item.type == "potion") {
hero.say("Potion! Yay!");
hero.moveXY(item.pos.x, item.pos.y);
hero.moveXY(66, 24);
} else if (item.type == "poison") {
hero.say("darn it! poison!");
hero.say("help me");
}
} else if (hero.pos.y === 40) {
hero.say("moving down");
hero.moveXY(hero.pos.x, hero.pos.y - 16); //this works
hero.say("At this point I SHOULD have changed my hero.pos.y to 24");
} else if (hero.pos.y === 24) {//here it works only with x
hero.say("moving to the steel door");
hero.moveXY(hero.pos.x + 16, hero.pos.y + 16);
} else if (hero.pos.y !== 24) {
hero.say("My Y-position hasn't changed!");
hero.moveXY(hero.pos.x + 16, hero.pos.y + 16);
}
}
Aucun commentaire:
Enregistrer un commentaire