[SOLVED] I would like some help with Operation 'Killdeer'

This is my code.

# Lure the ogres into a trap. These ogres are careful.
# They will only follow if the hero is injured.

# This function checks the hero's health 
# and returns a Boolean value.
def shouldRun():
    if hero.health < hero.maxHealth / 2:
        return True
    else:
        return False
enemy = hero.findNearestEnemy()
run = shouldRun()
while True:
    # Move to the X only if shouldRun() returns True
    if run == True:
        hero.moveXY(75, 37)
    # Else, attack!
    else:
        hero.attack(enemy)

I’ve read multiple topics for this one. It just makes me even more confused and I cannot get Alejandro to stop standing in one place after he says “…but it’s dead.” after he kills an ogre.
I’m stumped and I’ve no clue what to do.

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Welcome‌ ‌welcome‌ ‌to‌ ‌the‌ ‌forum!‌ ‌It‌ ‌is‌ ‌a‌ ‌lovely‌ ‌place‌ ‌where‌ ‌you‌ ‌can‌ ‌share‌ ‌all‌ ‌kinds‌ ‌of‌ stuff‌ ‌(appropriate‌ ‌of‌ ‌course),‌ ‌share‌ ‌bugs,‌ ‌and‌ ‌even‌ ‌get‌ ‌assistance‌ ‌for‌ ‌code!‌ ‌We‌ ‌suggest‌ ‌that‌ ‌you‌ ‌review‌ ‌this‌‌ topic‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ this topic‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ :partying_face: :partying_face:

Add parentheses to the end of this.

Move this inside the while True loop.

Lydia

My forehead hurts from how hard I facepalmed…
Thanks a million for helping me, Lydia!

1 Like

No problem!
Everyone makes mistakes!
Lydia

1 Like

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.