var enemy = hero.findNearestEnemy();
hero.buildXY("bear-trap", enemy.pos.x,enemy.pos.y);
hero.buildXY("fence", enemy.pos.x-2.5,enemy.pos.y-2.5);
hero.buildXY("fence", enemy.pos.x+2.5,enemy.pos.y+2.5);
hero.buildXY("fence", enemy.pos.x-2.5,enemy.pos.y+2.5);
hero.moveXY(hero.pos.x+5, hero.pos.y);
hero.buildXY("fence", enemy.pos.x+2.5,enemy.pos.y-2.5);
while(true) {
var flag = hero.findFlag();
var enemy = hero.findNearestEnemy();
var item = hero.findNearestItem();
if (flag) {
// What happens when I find a flag?
hero.blink(flag.pos);
hero.pickUpFlag(flag);
}
}
if (item) {
// What happens when I find an item?
if (hero.isReady("blink")) {
hero.blink(item.pos);
}
else {
hero.move(item.pos);
}
}
You’ve put two } brackets in after the if statements about flags. Those will close the while(true) loop, and the code for collecting items will never run.
For future reference, it’s useful if you can tell us which level you’re playing, and preferably please don’t tag lots of people when you’re asking general questions.