Help in Ogre Gorge Gouger

I really need help here is my code:

# Grab as much gold as you can, then retreat to your base and wall it off!
while hero.time < 20:
    # Collect coins
    hero.say("I should pick up a coin")
    while hero.gold < 60:
        nearest = hero.findNearest(hero.findItems())
        hero.move(hero.pos)
    
while hero.pos.x > 16:
    if hero>60:
    # Retreat behind the fence
        hero.moveXY(16, 38)
# Build a fence to keep the ogres out.
hero.buildXY("fence", 21, 38)


Could you please provide a link.

1 Like

here is the link:
https://codecombat.com/play/level/ogre-gorge-gouger?

you are not going to move anywere

I’ve tried:

move(nearest.pos)

but it doesn’t work

Well I’ve tried your code and changed it but it gave me the infinite loop error when you collected 60 coins.

yeah

(20 characters))))

though I found a problem

this should be

if hero.gold > 60:

oh and I’m tharin

((((((((((()))))

this is what it says:

I found the problem you can delete the second while loop in the hero.gold line change > to == and thats all

so it should be:

# Grab as much gold as you can, then retreat to your base and wall it off!
while hero.time < 20:
    # Collect coins
    hero.say("I should pick up a coin")
    
while hero.pos.x > 16:
    if hero.gold > 60:
    # Retreat behind the fence
        hero.moveXY(16, 38)
# Build a fence to keep the ogres out.
hero.buildXY("fence", 21, 38)


umm no keep your code the way it is but delete

and replace

to

if hero.gold == 60:

it still doesn’t work for me.

change that too: nearest = hero.findNearestItems()

try this >=instead of >

Delete the first while loop. Keep the second one like while hero.gold < 60. Then define the nearest item, and move to it if it exists.

Remove that.Also, make a variable like coin = hero.findNearestItem()
and move to it using hero.move(coin.pos)

i dont think thats necessary

Arent you suppose to use hero.move({"x" : 16, "y" : 38}) ?

image

At some point, you may collect all the coins your hero can see and there will not be a nearest item. When that happens, you hero can’t move to the nearest.pos and this error occurs. Simply add an if statement before the hero.move() command to ensure there is a value in the nearest variable before commanding the hero to move to that location.

2 Likes