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

Sleepwalkers help level thing level

My hero is staying still and I don’t know what’s going on. Anyone know why?

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 j in fenceMap:
    for i in 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.say("FOR GLORY")
while True:
    hero.shield()
    

I also tried

for j in fenceMap:
    for i in fenceMap:
        if fenceMap[i][j] == 1:
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

This is very close, try using range(len(fenceMap)) instead

thanks ill tyr it (20 chars)

i think i followed you wrongly

for j in range(len(fenceMap)):
    for i in range(len(fenceMap)):
        if fenceMap[i][j] == 1:
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

the hero builds fences normally, but the yetis kill the other peasants when they hit a fence, and I think it’s because of my code.

I don’t want to give you the answer because your very close.

[quote=“Needs_lots_help, post:1, topic:20795, full:true”]
My hero is staying still and I don’t know what’s going on. Anyone know why?

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 j in fenceMap:
    for i in 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.say("FOR GLORY")
while True:
    hero.shield()
    

I also tried

for j in fenceMap:
    for i in fenceMap:
        if fenceMap[i][j] == 1:
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

i feel like im so close

i still cant do it and im revisiting previous levels and I legit can’t figure out what i’m doing wrong at this rate

for j in range(len(fenceMap)):
    for i in range(len(fenceMap)):
        if fenceMap[i][j] == 1:
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

Using the new code you posted, re-read the comment on line 16…it doesn’t say anything about shielding or looping…

@Needs_lots_help Did you figure out the solution yet?

for j in fenceMap:
    for i in fenceMap:
        if fenceMap[i][j] == 1:  ??? i and j should be swapped because j is your 1st for loop i is 2nd
            place = convertCoor(i, j)
            hero.buildXY("fence", place.x, place.y)

# Move back to the village after building the fences.
hero.moveXY(starting position)

@brotherofall, did you try running this code? With the proper final line, this code runs perfectly.

Yes it runs correctly. @dedreous

The i and j needed to be in the correct positions as explained above otherwise it would be the wrong order.

for j … //
for i … //
convertCoor(j, i)

i is running inside the j for loop

brodudes i switched the j and i in the loop fencemap thing and it worked perfectly. thanks gyuys

1 Like