[SOLVED] Power points please help

i’m having trouble on this level. please help me. i don’t know what i’m doing wrong.
here’s my code:

spell = "VENI"
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

for i in range(len(powerMap)):
    for j in range(len(powerMap[i])):
        pointValue = powerMap[i][j]
        if pointValue and pointValue > 0:
            convert(i, j)
            hero.move({i.pos, j.pos})
            hero.say("VENI")
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.attack(enemy)

Here is the problem. Try to put what the convert function returns in a variabile pos then moveXY to pos.x and pos.y.
And if there is no enemy, then find the nearest item and moveXY to its position.
Do you need any more assistance at this level?

1 Like

thanks, i’ll try it (20)

1 Like

here’s my new code. it says that i and j are undefined.

for i in range(len(powerMap)):
    for j in range(len(powerMap[i])):
        pointValue = powerMap[i][j]
        if i and j and pointValue and pointValue > 0:
            convert(i, j)
            hero.moveXY(i.pos.x, j.pos.y)
            hero.say("VENI")
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.attack(enemy)
            coin = hero.findNearestItem()
            if coin:
                hero.moveXY(coin.pos.x, coin.pos.y)

Here put

posi = convert(i, j)

And here

MoveXY to posi.pos.
Do you need any more assistance at this level?

1 Like

apparently posi.pos is null.
here’s my code:

spell = "VENI"
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

for i in range(len(powerMap)):
    for j in range(len(powerMap[i])):
        pointValue = powerMap[i][j]
        if i and j and pointValue and pointValue > 0:
            posi = convert(i, j)
            hero.moveXY(posi.pos)
            hero.say("VENI")
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.attack(enemy)
            coin = hero.findNearestItem()
            if coin:
                hero.moveXY(coin.pos.x, coin.pos.y)

Here put:

hero.moveXY(posi.pos.x,posi.pos.y)

Do you need any more assistance at this level?

1 Like

it says "cannot read x of undefined’ for this line:
hero.moveXY(posi.pos.x, posi.pos.y)

here’s the rest of the code:

spell = "VENI"
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

for i in range(len(powerMap)):
    for j in range(len(powerMap[i])):
        pointValue = powerMap[i][j]
        if i and j and pointValue and pointValue > 0:
            posi = convert(i, j)
            hero.moveXY(posi.pos.x, posi.pos.y)
            hero.say("VENI")
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.attack(enemy)
            coin = hero.findNearestItem()
            if coin:
                hero.moveXY(coin.pos.x, coin.pos.y)

Try to delete this. Does it work now?

1 Like

the same result came out.

Can you send me the link to the level?

1 Like

https://codecombat.com/play/level/power-points?

Here put

hero.moveXY( posi.x, posi.y)

Have you completed the level?

1 Like

my hero’s not moving. why?
here’s my code:

spell = "VENI"
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

for i in range(len(powerMap)):
    for j in range(len(powerMap[i])):
        pointValue = powerMap[i][j]
        if pointValue and pointValue > 0:
            posi = convert(i, j)
            hero.moveXY(posi.x, posi.y)
            hero.say("VENI")
            enemy = hero.findNearestEnemy()
            while enemy == True:
                if enemy:
                    hero.attack(enemy)
            item = hero.findNearestItem()
            if item:
                hero.moveXY(item.pos.x, item.pos.y)

Here put only
while enemy and enemy.health > 0 and in the while loop attack the enemy.
Do you need any more assistance at this level?

1 Like

i beat the level :partying_face:

1 Like

Then congratulations for completing the level! :partying_face:

1 Like