Return-to-thornbush-farm


Peasant spawns on top. Orge kills peasant. :с

1 Like

You have to build a fire-trap to kill the ogre instead of a fence.

hero.buildXY(“fire-trap”, x, y)

Hope this helps

Oh, my stupid mistake! Thanks!

Unbeatable!!! >:(
I hate this level, I can’t beat it

What do you need help with?

@_TD_RodYT : I don’t know if this was @Simon_Yang’s problem, but I’m also running into trouble.

I’ve followed the code offered:

# The function maybeBuildTrap defines TWO parameters!
def maybeBuildTrap(x, y):
    # Use x and y as the coordinates to move to.
    hero.moveXY(x, y)
    enemy = hero.findNearestEnemy()
    if enemy:
        # Use buildXY to build a "fire-trap" at the given x and y.
        hero.buildXY("fire-trap", enemy.pos.x, enemy.pos.y)

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)
    

But then my hero just goes running over to the nearest enemy, and won’t build anything.

I’m tempted to cheap shot out, since I have a shield with a good bash, and could just have him bash the ogres to keep 'em off the peasants, but I’d rather try and make it through.

1 Like

Whoops. Nevermind.

My issue was that I coded the hero to build the trap under the enemy ("fire-trap", enemy.pos.x, enemy.pos.y) instead of at the generic variable x and y.

3 Likes

why is my code not working

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

Hey @floridamanog sorry to reply so late but

change the

to

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

change

to

    maybeBuildTrap(25, 34)

and change the last buildXY to

maybeBuildTrap(43, 20)