Greed traps (python)[SOLVED]

My hero just passes the x-mark before the coin comes. I’m getting frustrated.

# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
    # Move to the given x,y postion
    hero.moveXY(x, y)
    # Search a coin and  if you see it, build a "fire-trap"
    item = hero.findNearestItem()
    if item:
        hero.buildXY("fire-trap", x, y)
    pass
while True:
    # Call maybeBuildTrap for the top left passage.
    maybeBuildTrap(12, 56)
    # Now for the top right passage.
    hero.moveXY(68, 56)
    # Now for the bottom right passage.
    hero.moveXY(68, 12)
    # Now for the bottom left passage.
    hero.moveXY(12, 12)
1 Like

You have to check if there is an item and if the item type is coin
Lydia

1 Like

Still not working.

# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
    # Move to the given x,y postion
    hero.moveXY(x, y)
    # Search a coin and  if you see it, build a "fire-trap"
    item = hero.findNearestItem()
    if item and item.type == "coin":
        hero.buildXY("fire-trap", x, y)
    pass
while True:
    # Call maybeBuildTrap for the top left passage.
    maybeBuildTrap(12, 56)
    # Now for the top right passage.
    hero.moveXY(68, 56)
    # Now for the bottom right passage.
    hero.moveXY(68, 12)
    # Now for the bottom left passage.
    hero.moveXY(12, 12)
1 Like

hmm maybe its your equipment? show your armor and a screenshot of what shappening

You need a distance to item instead, like this

    if item and hero.distanceTo(item) < 30:
        hero.buildXY('fire-trap', x, y)

The rest is good

You need to do maybeBuildTrap() with those coordinates, like this:

But with different coordinates (68 , 56; 68, 12; 12, 12)
Lydia

1 Like

Lol thank you so much Lydia!
got it! :grin:

2 Likes

Glad to help!
Lydia
20

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.