Help with To Arms

I need help with the level To Arms here is my code:

# Ogres are going to attack soon.
# Move near each of tents (to the X marks)
# say() something at each X to wake your soldiers.
# Beware: leave the camp when the battle begins!
# Ogres will send reinforcements if they see the hero.

# The sergeant knows the distance between tents.
sergeant =  hero.findNearest(hero.findFriends())

# The distances between the X marks.
stepX = sergeant.tentDistanceX
stepY = sergeant.tentDistanceY
# The number of tents.
tentsInRow = 5
tentsInColumn = 4

# The first tent mark has constant coordinates.
firstX = 10
firstY = 14

maxY = firstY + tentsInColumn * stepY
maxX = firstX + tentsInRow * stepX

# Use nested loops and visit all 20 tents.
# IMPORTANT: move row by row - it's faster.
for y in range(firstY, maxY):
    for x in range(firstX, maxX):
        hero.moveXY(x, y)
        hero.say("Wake Up!")

# Now watch the battle.
hero.moveXY(2, 40)

My hero will just move one step at a time instead of moving to each of the x’s and then when he is done he will just go back instead of going to the next row. Does anybody know what’s wrong?

Speedy, this is the issue in your code:

Your for loop only has 2 arguments which means it will just increase by 1 each time through. If you want it to increase by the distance between each tent, you need to have a 3rd argument. It should look something like this:

for y in range(firstY, maxY, Distance between Y tents here):
for x in range(firstX, maxX, Distance between X tents here):
Hope this helps!


oh wow that did it! Thanks so much!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.