Help Thunderhooves

I need assistance with “Thunderhooves” if anyone could help that would be very helpful

here is my code btw

while True:
        yak = hero.findNearestEnemy()
if yak:
    # If yak.pos.y is greater than hero.pos.y
    if yak.pos.y > hero.pos.y:
        # buildXY a “fence” 10m below the yak.
            hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
    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(hero.pos.x + 10, hero.pos.y)
        pass

All of that must be in your while true loop.

@abc now it says that “else”: statement is unsupported!!

What is your code right now?

while True:
    if yak:
    # If yak.pos.y is greater than hero.pos.y
        if yak.pos.y > hero.pos.y:
        # buildXY a “fence” 10m below the yak.
            hero.buildXY("fence", yak.pos.x, yak.pos.y - 10)
    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(hero.pos.x + 10, hero.pos.y)
        pass

@abc

Indent the else
29 chars

Indent the else statement to align it with the if statement checking for a yak.

while True:
    yak = hero.findNearestEnemy()
    if yak:
        #code
    else:
        #move

i tried exactly that but yet still it won’t agree with my code :thinking:

@abc

What you have is this:

while true:
    #code
else:

How do you compare an else statement to a while true loop? You cannot. It needs to be paired with an if statement. First, have a while true loop. Then inside of that, find the nearest enemy and define it as yak. then check if the yak exists. If it does, then check if its position y is greater than your hero’s position y. If also that is true then, build a fence 10m below the yak. If the yak is above your hero, then build a fence 10m above the yak. If there is no yak, then move 10m to the right.

while True:
    yak = hero.findNearestEnemy()
    if yak:
        #check if the yak's position y is greater than your hero's position y
            #build a fence below
       #else, your hero's position y is greater than the yak's position y
            #build a fence above
    else: #there is no yak
        #move right

i see thank you very much

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