Double gaps - grasp ogre position (python)

Welcome to the forum @Samu2015 ! :partying_face: This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Don’t forget to read the guidelines if you haven’t yet. Have a great time!

Please for the next time, format your full code using this button to better help you :slight_smile:

As for this time, it’s fine

Get the hero and the peasant to the south.
The function move your hero down along the center line.
def moveDownCenter():
    x = 40
    y = hero.pos.y - 12
    hero.moveXY(x, y)

The function build a fence on the right of something.
def buildRightOf(something):
    # buildXY a “fence” 20 meters to something’s right.
    x = 40 + 20
    y = hero.pos.y
    hero.buildXY(“fence”, x, y)
    pass

The function build a fence on the left of something.
def buildLeftOf(something):
    # buildXY a “fence” 20 meters to something’s left.
    x = 40 - 20
    y = hero.pos.y
    hero.buildXY(“fence”, x, y)
    pass

while True:
    ogre = hero.findNearestEnemy()
    coin = hero.findNearestItem()

    if ogre.pos.x < 40:
        buildRightOf(ogre)
    elif:
        buildLeftOf(ogre)
    elif coin:
        hero.move(coin)
    moveDownCenter()
pass

So in both of the functions that you build in them, the x should be +20 or -20 the position of the parameter you entered in paranthesis called “something”, try that, if it didn’t work, then please post your code after editing :slight_smile:

1 Like