While ogres were sleeping


#1
# Enemies are sleeping. It's the perfect time for sabotage!
points = [{"x": 21, "y": 8}, {"x": 33, "y": 8},
    {"x": 45, "y": 8}, {"x": 57, "y": 8}, {"x": 68, "y": 8},
    {"x": 68, "y": 18}, {"x": 68, "y": 28}, 
    {"x": 68, "y": 38}, {"x": 68, "y": 48},
    {"x": 68, "y": 58}, {"x": 56, "y": 58},
    {"x": 44, "y": 58}, {"x": 32, "y": 58}, 
    {"x": 20, "y": 58}, {"x": 10, "y": 60}]

pointIndex = 0;

while pointIndex < len(points):
    point = points[pointIndex];
    hero.moveXY(point["x"], point["y"])
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    # Attack only if the enemy.team is "ogres"
    # AND the enemy's health is less than 10
    if enemy:
        if enemy.team == "ogres" and enemy.health < 10:
            hero.attack(enemy)
        
    # Collect a coin if coin.value is less than 5
    # AND its distance is less than 7
    if coin:
        if coin.value < 5:
            if hero.distanceTo(coin) < 7:
                hero.moveXY(coin.pos.x, coin.pos.y)
    # Attack only if the enemy.health is less than 10
    # AND the enemy's type is "skeleton".
    if enemy:
        if enemy.team == "skeleton" and enemy.health < 10 :
            hero.attack(enemy)
        
    pointIndex += 1

my hero doesn’t attack the skeleton can someone tell me why that is


#2

Attack only if the enemy.health is less than 10 AND the enemy’s type is “skeleton”.


#3

thats what my code says to do


#4

And you write :
if enemy.team == “skeleton”


#5

whats wrong with it
?


#6

Correct is:
if enemy.type== “skeleton”


#7

i dont see what ur trying to point out


#8

Not:
if enemy.team == “skeleton” and enemy.health < 10

but:
if enemy.type == “skeleton” and enemy.health < 10 :


#9

i did that and it still didnt work


#10

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)