I used very similar code in this level, but it did not work. I had my friend (who already finished this level) send me this code. It works on his computer, but not mine. I am confused.
// The coin field has been seeded with vials of deadly poison.
// Ogres are attacking, while their peons are trying to steal your coins!
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
// Attack the enemy only if the type is NOT equal to "peon".
if(enemy.type != "peon") {
hero.attack(enemy);
}
}
var item = hero.findNearestItem();
if(item.type != "poison") {
// Gather the item only if the type is NOT equal to "poison".
hero.moveXY(item.pos.x, item.pos.y);
}
}
Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!
Hi, most of us have never used the scholastic version of CodeCombat (I have) and won’t know which level you are talking about, could you please send the level name?
Also, the reason it works for him but not for you is because the seed is random every time, so you have to change it.
Hi @n413673 and welcome to the forum This is a friendly place where you can ask for help on levels, report bugs and chat with other people. Enjoy your time!
I think Moon meant change the code as the seed is random which means the seed will be different each time without you deciding how it will be like