Argument Error in my code

I don’t understand why there is an error because soldiers are defined but it says there is nothing to command. Why is that? The error is ArgumentError: Hero placeholder needs something to command

def findSoldierOffset(soldiers, i):
    soldier = soldiers[i]
    angle = i * 360 / len(soldiers)
    return radialToCartesian(5, angle)

# This function does the math to determine the offset a soldier should stand at.
def radialToCartesian(radius, degrees):
    radians = Math.PI / 180 * degrees
    xOffset = radius * Math.cos(radians)
    yOffset = radius * Math.sin(radians)
    return {"x": xOffset, "y": yOffset}

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

# Use findByType to get an array of your soldiers.
while True:
    soldiers = hero.findByType("soldier")
    # Use a for-loop to iterate over range(len(soldiers)).
    for soldeirs in range(len(soldiers)):
        # Find the offset for a soldier.
        findSoldierOffset(soldiers)
        offset = radialToCartesian()
        # Add the offset.x and offset.y to the peasant's pos.x and pos.y.
        moveTo = {"x": peasant.pos.x + offset.x, "y": peasant.pos.y + offset.y}
        # Command the soldier to move to the new offset position.
        soldiers = hero.findByType("soldier")
        hero.command(soldiers, "move", moveTo)
    # The hero should keep pace with the peasant!
    hero.move({"x": hero.pos.x + 0.2, "y": hero.pos.y})

Sometimes, if the soldier doesn’t exist, it will put soldier as none, so you can add: if soldier: and then the command after it, this way, you can make sure the soldier variable isn’t null when you are trying to command it

@Aya
I did that but it says the same error

Code please (20chars)

# You must escort a powerful magical ring back to town to be studied.
# The goal is to escape, not fight. More ogres lurk in the surrounding mountains!
# Make a circle of soldiers around the peasant!
# We give you two functions to help with this:

# findSoldierOffset figures out the position a soldier should stand at in relation to the peasant.
# The first argument 'soldiers' should be an array of your soldiers.
# The second argument 'i' is the index of the soldier (in soldiers) you want to find the position for
def findSoldierOffset(soldiers, i):
    soldier = soldiers[i]
    angle = i * 360 / len(soldiers)
    return radialToCartesian(5, angle)

# This function does the math to determine the offset a soldier should stand at.
def radialToCartesian(radius, degrees):
    radians = Math.PI / 180 * degrees
    xOffset = radius * Math.cos(radians)
    yOffset = radius * Math.sin(radians)
    return {"x": xOffset, "y": yOffset}

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

# Use findByType to get an array of your soldiers.
while True:
    soldiers = hero.findByType("soldier")
    # Use a for-loop to iterate over range(len(soldiers)).
    for soldiers in range(len(soldiers)):
        # Find the offset for a soldier.
        findSoldierOffset(soldiers)
        offset = radialToCartesian()
        # Add the offset.x and offset.y to the peasant's pos.x and pos.y.
        # Command the soldier to move to the new offset position.
        soldiers = hero.findByType("soldier")
        if soldiers:
            moveTo = {"x": peasant.pos.x + offset.x, "y": peasant.pos.y + offset.y}
            soldiers = hero.findByType("soldier")
            hero.command(soldiers,"move", moveTo)
    # The hero should keep pace with the peasant!
    hero.move({"x": hero.pos.x + 0.2, "y": hero.pos.y})

I guess this level is ring bearer.

For this one, you need to use the function findSoldierOffset which you have done, but you didn’t put in enough parameters, you need to put the unit, and the cursor for the for-loop, like soldiers in this case (and i suggest you name it something different, like i or soldier) and you should also save it in a variable. So it should look like something like this: soldierOffset = findSoldierOffset(soldiers, i)

The variable you have under it offset is unnecessary, we have used radialToCartesian in the function findSoldierOffset, so you can delete that.

You have defined soldiers again inside the for-loop, which isn’t required, you should remove that, too.

And i guess what you have left should work

Which level is this?