Can someone please have a look at my codes of Long-Range Division -see below snip.
No sure why the hero is killed at the end.
Below are my codes
Destroy the mines!
Use say
to call out the range to the mines.
Use division to calculate the range.
enemy = hero.findNearestEnemy()
distanceToEnemy = hero.distanceTo(enemy)
Say first Range: distanceToEnemy divided by 3
hero.say(“first Range”+ distanceToEnemy/3)
hero.say (“Fire!”)
Say second range: distanceToEnemy divided by 1.5
hero.say(“second Range”+ distanceToEnemy/1.5)
hero.say (“Fire!”)
hero.say(“Woo hoo!”)
hero.say(“Here we go”)
hero.say(“Charge!!”)
while True:
hero.findNearestEnemy()
hero.attack(enemy)
hero.attackDamage
You didn’t define the enemy variable, so this results an error, do this instead:
while True:
enemy = hero.findNearestEnemy() # Define the enemy!
if enemy: # Check for the existance of the enemy
hero.attack(enemy)
Please format your code, and, as @Watamelon said, you have to define enemy
before using it