Long Range Division Help


#1

Hey everyone I have been having some trouble on Long Range Division. It says line 8 distance isn’t defined.

here is the code:

enemy = hero.findNearestEnemy()
distanceToEnemy = hero.distanceTo(enemy)
# Say first Range: distanceToEnemy divided by 3
if distance == hero.distanceTo(enemy) / 3:
    hero.say("Fire!")
# Say second range: distanceToEnemy divided by 1.5
if distamce == hero.distanceTo(enemy) / 2:
    hero.say("Fire!")

# Say these things for motivation. Really. Trust us.
hero.say("Woo hoo!")
hero.say("Here we go!")
hero.say("Charge!!")

# Now, use a while-true loop to attack the enemies.
while True:
    hero.attack(enemy)

Thanks for the help!


#2

I noticed one problem with your code and that is on what looks like line 7: you spelled distance wrong, other than that I see no problems.


#3

distanceToEnemy is not the same variable as distance


#4

Oh…ok I’ll fix that. Thanks for the help.


#5

Wait…I may look stupid, but what do you mean @Serg by distanceToEnemy is not the same?


#6

I just wanna ask you,wat the heck is distamce?


#7

hero.distanceTo(something) is how far a unit is from the hero. :slight_smile: