Raiders of the long dark help!


#1

this is my code:

# Your goal is to protect the peasant and move to the right.
# Arryn Stonewall will defend the front, and command the soldiers.
# You need to cover the rear and command the peasant.

arryn = hero.findByType("raider")[0]
peasant = hero.findByType("peasant")[0]

def chooseHeroStrategy():
    # Return either "fight" or "advance".
    # Try to stay 5m behind the peasant when not fighting.
    # Don't get more than 15m away from the peasant.
    enemy = hero.findNearestEnemy()
    if enemy:
        return "fight"
    if hero.distanceTo(peasant)>5:
        return "advance"
        
    pass

def heroFight():
    # Stop the ogres from rushing past you to get to the peasant!
    # Hint: try to slow them down if you can
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        
    pass

def heroAdvance():
    # Stay behind the peasant
    hero.moveXY(peasanr.pos.x-5, peasant.pos.y)
    pass

def choosePeasantStrategy():
    # Return "follow", "build-above", or "build-below"
    # Hint: use isPathClear() to determine where the hallways are
    if peasant.distanceTo(arryn)>5:
        return "follow"
    if peasant.isPathIsClear(peasant.pos.x, peasant.pos.y + 5):
        return "build-above"
    if peasant.isPathIsClear(peasant.pos.x, peasant.pos.y - 5):
        return "build-below"
    pass

def peasantAdvance():
    # Keep the peasant behind Arryn and her soldiers.
    hero.command(peasant, "move", {'x':arryn.pos.x-5,'y':arryn.pos.y)
    pass

def peasantBuild(x,y):
    # Command the peasant to build a palisade.
    hero.command(peasant, "palisade", {'x':x,'y':y})
    pass

while True:
    heroStrategy = chooseHeroStrategy()
    if heroStrategy == "fight":
        heroFight()
    elif heroStrategy == "advance":
        heroAdvance()
    
    peasantStrategy = choosePeasantStrategy()
    if peasantStrategy == "build-above":
        peasantBuild(peasant.pos.x, peasant.pos.y + 5)
    elif peasantStrategy == "build-below":
        peasantBuild(peasant.pos.x, peasant.pos.y - 5)
    elif peasantStrategy == "follow":
        peasantAdvance()
    


#2

I believe this is the problem:

hero.moveXY(peasanr.pos.x-5, peasant.pos.y)

You mispelled peasant


#3

Is that it?(scroll down for more code)


#4

Did you try what @_TD_RodYT mentioned first? Or do you know something else about the code?


#5

Also, make sure you redefine the variable “Arryn” inside a function. Sometimes, a function cannot see a variable outside of it during the calling procedure so make sure you redefine arryn = hero.findByType(“raider”)[0]


#6

yeah but there was still an error a


#7

Try what he said…


#8

The error also may be when you command the peasant to move, you have no ending parenthesis


#9

It seems like I found a different code that helps!(It worked!)