Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Raiders of the long dark help!


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"

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"):

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

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"

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

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

while True:
    heroStrategy = chooseHeroStrategy()
    if heroStrategy == "fight":
    elif heroStrategy == "advance":
    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":


I believe this is the problem:

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

You mispelled peasant


Is that it?(scroll down for more code)


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


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]


yeah but there was still an error a


Try what he said…


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


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

1 Like

Mod edit: Please do not post requests for assistance with the same issue in multiple locations. You will not receive assistance any faster.