Sleepwalkers Python

Hi everyone, I don’t really know what is wrong with my code and if there’s a lot of errors, it’s because my coding isn’t very good. This is my code:

# Our sleepwalking peasants are returning.
# But sleeping yetis are also coming.
# Build fences to let peasants through and stop yetis.

# Senick's prepared the grid map how to build fences.
hunter = hero.findNearest(hero.findFriends())
fenceMap = hunter.getMap()

# This function converts grid into XY coordinates.
def convertCoor(row, col):
    return {'x': 34 + col * 4, 'y': 26 + row * 4}

# Iterate over fenceMap and build at fence at all 1s.
for i in range(len(fenceMap)):
    for j in range(len(fenceMap):
        if fenceMap[i] == 1  and fenceMap[j] == 1:
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

# Move back to the village after building the fences.
hero.moveXY(30, 18)

I get that often when there’s something wrong with loop formatting…

Does it tell you which line has the error?

The “for j in range(len(fenceMap))” part

In the code you’re missing the second closing parenthesis ) on that line.


I was going to just type that :+1:

1 Like

Ooooh! Thanks so much!

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