Siege of StoneHold Hero Does Nothing (Python)


#1

Hello,
I do not understand why my code does not run. The hero just sits there and preforms no action, not even shield.
Is the IDE not powerful enough to evaluate the and command or the various elifs?

enemy = hero.findNearestEnemy()
flag = hero.findFlag("green")
ready = hero.isReady("cleave")

while True:
    if enemy and ready :
        hero.cleave(enemy)
    elif enemy:
        hero.attack(enemy)
    elif flag:
        hero.findFlag("green")
    elif hero.health < 200: 
        hero.moveXY(20, 69)
    else:
        hero.shield()
    

#2
  • enemy – You only search for an enemy once.
    You should search for enemies continuously.
    (No enemy found in the beginning means the lines if enemy and ready: and elif enemy: always evaluate to False)

  • flag – In the while True: loop
    The line, elif flag:
    Maybe you meant elif not flag:? (and you also need to move to the flag and pick it up)
    (No flag found in the beginning means that elif flag: will always evaluate to False)

  • ready – You never update this variable inside the while True: loop.
    Instead of if enemy and ready:, you can use if enemy and hero.isReady("cleave"):
    Then, you won’t need the ready variable anymore.
    (In your code right now, ready will always be True)

So, here’s your code again, but with comments about how it’s working:

enemy = hero.findNearestEnemy()    # you should put this in the loop so it can update continuously
flag = hero.findFlag("green")      # same with this
ready = hero.isReady("cleave")     # and this

while True:
    if enemy and ready :       # this always evaluates to (false and true) = false
        hero.cleave(enemy)         # (this code doesn't run)
    
    elif enemy:                # this always evaluates to false
        hero.attack(enemy)         # (this code doesn't run)
    
    elif flag:                 # this always evaluates to false
        hero.findFlag("green")     # (this code doesn't run)
    
    elif hero.health < 200:    # this works as expected
        hero.moveXY(20, 69)
    
    else:                      # and this is why you've noticed
        hero.shield()          # your hero shielding all the time

#3

So one issue I found. The hero.health never gets invoked because there are so many enemies. How can I set it so it breaks out and goes to the health if it goes below 200?


#4

That shouldn’t be the reason why that if statement fails. The 3 conditional checks before it always fail (except if you have the infinite range/see-through-walls glasses).

Fix the other issues first and worry about refilling on health later.
Really, I don’t see anything wrong with elif hero.health < 200:.