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

Kithgard brawl problem please

#1
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        else:
            hero.attack(enemy)
    else:
        if hero.findNearestItem():
            hero.attack(hero.findNearestItem())
        else:
            hero.say("message")

Hello, can someone explain me why does my hero stop attacking after finding health pot?

#2

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly

#3

actually i was wondering, how the heck would someone read my “copy/paste” code and concluded “ah ok i am beginner they possibly are code-reading machines” :wink:

#4

You can’t attack items. Try moving to the item’s position instead.

#5

but i actually get this health pot but after getting it, it stops

#6

am i right that after getting to health pot position, my hero tries to attack it and thats why he stops?

#7

I don’t understand how you’re hero could move to the coin. Like Munkey said, you can’t attack an item. You should get a big red cross error around your hero and not be able to do anything else.
Is this (the code you posted) still your current code?
:lion: :lion: :lion:

#8

I can quarantee hero will move to Item position. Try it. Is this some kind of bug?

#9

It’s a previously reported bug. Can I ask why you’re trying to attack an item?

#10

Cause i am beginner and i instinctevely thougt its ok. I havent discovered item.pos. commands.