[SOLVED] Return to thornbush farm help

I have looked at other posts and have found nothing that helps with my problem, here is my code

 The function maybeBuildTrap defines TWO parameters!
def maybeBuildTrap(x, y):
    # Use x and y as the coordinates to move to.
    enemy = hero.findNearestEnemy()
    if enemy:
        pass
        # Use buildXY to build a "fire-trap" at the given x and y.
        hero.buildXY("fire-trap", 42, 50)
while True:
    # This calls maybeBuildTrap, with the coordinates of the top entrance.
    maybeBuildTrap(43, 50)
    
    # Now use maybeBuildTrap at the left entrance!
    maybeBuildTrap(25.34)
    # Now use maybeBuildTrap at the bottom entrance!
    maybeBuildTrap(43,20)

I should probably describe what’s happening.

When I run the code, no error messages pop up, but my person simply runs to each X but places no trap

I wonder how your hero runs to the X when there’s no “hero.moveXY(x, y)” in your code :thinking:.
However, I think you need to add it (it’s already in the original unsolved code):


(Edited, credits to brooksy125)

…so that your hero moves first to the (x, y) position, then builds the trap on it
when the function maybeBuildTrap() is called.

One quick catch, you have a period instead of a comma in this line.

maybeBuildTrap(25.34)

Also, in the function, don’t declare a static number value in the buildXY(), use the x, y variables that the function receives. Keep in mind that the values you input when calling the function carry into the function as the new variables used within that function. If that doesn’t make sense, check below.

hero.buildXY("fire-trap", x, y)
1 Like

Ohhh… right, I think I didn’t see those too…:sweat: