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

Ring Bearer help

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 = self.findByType("soldier") 
    # Use a for-loop to iterate over range(len(soldiers)).
    for i in range(0, len(soldiers)):
        # Find the offset for a soldier.
        offset = findSoldierOffset(soldiers, i)
        # 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.
        hero.command(soldiers[i], "move", offset)
        # The hero should keep pace with the peasant!
    hero.move({"x": hero.pos.x + 0.2, "y": hero.pos.y})

All of my soldiers start moving, but they all go to the bottom left corner.
and only me and hector are moving.

In your while True loop, you define a position, moveTo, and then in the hero.command line, you call a position called, offset. The purpose of defining the variable, offset, is to use the output of the function to compute the moveTo position. Are you supposed to command the soldiers to move to offset or to the position defined in moveTo? If you’re not going to use a variable, why define it at all?