Need Help On Power Point | Python


#1

Need help on power points.Can’t seem to get a correct code no matter what.


#2

So here’s the script:

spell = “VENI”
#The map of points is a 2D array of numbers.
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

#This function converts grid into x-y coordinates.
def convert(row, col):
return {‘x’: 16 + col * 12, ‘y’: 16 + row * 12}

#Loop through the powerMap to find positive numbers.
#First, loop through indexes of rows.
for i in range(len(powerMap)):
# Each row is an array. Iterate through it.
for j in range(len(powerMap[i])):
# Get the value of the i row and j column.
pointValue = powerMap[i][j]
# If it’s a positive number:
if pointValue > 0:
# Use convert to get XY coordinates.
pos = convert(i, j)
# Move there, say “VENI” and be prepared!
hero.moveXY(pos.x, pos.y)
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
hero.say(spell)
if enemy:
hero.attack(enemy)
elif item:
hero.moveXY(item.pos.x, item.pos.y)


#3

Please use the proper formatting when posting your code. It’s really easy (just two steps). You just have to copy it from the game - don’t copy it from this board - copy it from the game so that we can see the formatting and structure. There are many people here who are able and willing to assist, but you’ve got to help us help you.

Button01

Also, please include any error messages or a very brief description of what’s going on (e.g. hero not moving, hero not attacking, hero not collecting items, etc.)


#4

@MunkeyShynes the red is kinda getting cringey, tbh… just saying.


#5
# You need to find and destroy 3 skeletons.
# Skeletons and items are summoned at points of power.
# Move to a point and say the spell: "VENI".
# To find the required points, use the wizard's map.
# 0s are bad points. Positive numbers are good.

spell = "VENI"
# The map of points is a 2D array of numbers.
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

# This function converts grid into x-y coordinates.
def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

# Loop through the powerMap to find positive numbers.
# First, loop through indexes of rows.
for i in range(len(powerMap)):
    # Each row is an array. Iterate through it.
    for j in range(len(powerMap[i])):
        # Get the value of the i row and j column.
        pointValue = powerMap[i][j]
        # If it's a positive number:
        if pointValue > 0:
            # Use convert to get XY coordinates.
            pos = convert(i, j)
            # Move there, say "VENI" and be prepared!
            hero.moveXY(pos.x, pos.y)
            enemy = hero.findNearestEnemy()
            item = hero.findNearestItem()
            hero.say(spell)
            if enemy:
                hero.attack(enemy)
            elif item:
                hero.moveXY(item.pos.x, item.pos.y)

All that’s wrong is that the top left hand corner says “incomplete”


#6

Two things:

  1. Think about the order in which you want to do things. Once you move to a new position you need to say the spell before anything else. You’re defining new variables before you say the spell which is causing the code to iterate through your if and elif conditionals before you want it to.

  2. You are attacking but only once and not enough to kill the skeletons. Add some code so that while enemy.health is greater than zero, you attack.