[SOLVED] Help plz I'm stuck on thunderhooves

My code isn’t working here it is:

# Build a "fence" above or below when you see a yak.
x = hero.pos.x
y = hero.pos.y
while True:
    yak = hero.findNearestEnemy()
    if yak:
        # If yak.pos.y is greater than hero.pos.y
        if yak.pos.x > hero.pos.y:
            
            # buildXY a "fence" 10m below the yak.
            hero.buildXY("fence",yak.pos.x,yak.pos.y - 10)
        # else: 
        else:
            # buildXY a "fence" 10m above the yak.
            hero.buildXY("fence",yak.pos.x,yak.pos.y + 10)
        pass
    else:
        # moveXY right 10m towards the oasis.
        hero.moveXY(x, y)
        pass
 x += 10

Can you send a link to the level?
Lydia

Right here

You can just delete this:

and
this:

And replace this:

with this:
hero.moveXY(hero.pos.x + 10, hero.pos.y)
Lydia

1 Like

I’ll try that 200000000

1 Like

If the first yak comes from the top it kills me. if the second yak comes from the bottom it kills me. if the third yak comes from the top it kills me.

Sorry, I don’t quite understand what you mean. If you fixed what I told you to fix, everything should be good.
Lydia

please dont post solutions like that thanks it disables the ability to learn from that level thanks!

2 Likes

and @chaboi3000 please delete the solution

I think it’s because you have said if the yak.pos.x is greater than hero.pos.y, then build a fence below the yak. Shouldn’t the yak.pos.x be yak.pos.y if you are comparing it to hero.pos.y

2 Likes

also it is @Chaboi_3000 not @chaboi3000

@Lydia_Song is correct with her adjustment on your hero.move(x,y), you need to give proper coordinates since you didn’t define the x and y variables.

And good catch by @abc on the x vs y coordinate correction. Typos and calling the wrong variables will sneak in an wreak havoc on your code every time and they can be difficult to spot.

2 Likes

Thank I didn’t notice that i’ll try it

Yours is also a solution :smiley:

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