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

[SOLVED] SarvenSum - defeat ogres

Hy guys, i’ve another problem whit new level…

I complete the level but dont defeat the ogres becous hero move to x red …
there is a time metod? like to
if enemy <0:
hero.wait(30sec)
There is my code:

def scappa():
    enemy = hero.findNearestEnemy()
    if enemy and enemy.health > 0:
        hero.attack(enemy)

    else:        
        hero.moveXY(redX.x, redX.y)

whiteX = {'x':27, 'y':42}
redX = {'x':151 , 'y': 118}
hazards = hero.findHazards()
hero.moveXY(whiteX.x, whiteX.y)
max = 0
min = 999
index= 0
while index < len (hazards):
    item = hazards[index]
    if item.value > max:
        max= item.value
    if item.value < min:
        min = item.value
    index +=1

hero.say(max+min)
scappa()

O_o … i’ve solved, but i dont understand…
only change this line in function:

# from
    else:        
        hero.moveXY(redX.x, redX.y)
# to
    else:        
        hero.move(redX)

now works fine, but i don’t understand why it work? :smile:

Try asking @Luke10, he was the one who changed it to solved. :man_shrugging:
Edit: I’ve removed the [SOLVED] Tag.

See The new boots and move vs moveXY for explanation of your question. Replace loop: with while True: and self with hero in the old post.
So while using moveXY(x, y) you block all other actions and using move(position) you are much more flexible. Because move(position) works only within a loop the changes in your code will be:

def scappa():
   # code...   
        hero.move(redX)
# code...
while True:
    scappa()

why is the function called scappa?

Because i’m a italian :slight_smile:

Thanks xython for explanation :slight_smile:

Yeah I changed it because of this:

He stated that he solved the issue so I changed it…

Also in the edits he changed what you put back to what I put:
It went from this:


to this:

:fox_face::fox_face::fox_face: