Python minesweeper - character keeps moving back to the same spot


#1

Hi! Just started Code Combat a couple days ago and it’s awesome! I’m having trouble with a couple levels though and I’m not sure what I’m doing wrong.

In the level minesweeper you have to move to an item (gold) and set off the mines, but for me the character moves to the first gold piece then stops. When I run this the code gets stuck on line 18 and just keeps moving back to that same spot, rather than finding a new item. I’ve even tried adding a moveXY command after to help the character find the next gold piece, but it holds onto that first set of coordinates and moves back.

Any advice?

# Lead the peasants and healer through the minefield.
# Move to the coins to trigger the fire traps.
# The mines are randomized, so use findItems.
# Move back 10m and ask for a "heal" if your health is low.

item = self.findNearest(self.findItems())
healthlow = self.health < self.maxHealth / 3
healthhigh = self.health > self.maxHealth / 3
x = self.pos.x
y = self.pos.y


loop:
    if item:
        itemPos = item.pos
        itemx = itemPos.x
        itemy = itemPos.y
        self.moveXY(itemx,itemy)
            
    elif healthlow:
        self.moveXY(x-10,y)
        self.say("One heal please!")

#2

Figured it out, I didn’t realize all the items listed at the top had to be inside the loop.