The argument is what is inside the parenthesis of the method.
You have not done the second part of my initial post. You do not need to define your variable twice.
The argument is what is inside the parenthesis of the method.
You have not done the second part of my initial post. You do not need to define your variable twice.
Hello @MunkeyShynes I have done some trial and error with the information an I finally got my mage to Attack, so thank you very much for you help!
I’m only a beginner so I am sorry if I made you loose time with me and my misunderstandings.
Again, Thank you very much.
@MunkeyShynes I have yet another problem but now that I understand more I think I will figure this out easier so my mage attack but 4 seconds before the code finishes, it says it gets too tired and it stops attacking. here is my code:
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 0
if enemy:
result = hero.distanceTo(enemy)
return result
while True:
# Call nearestEnemyDistance() and save the result in the variable enemyDistance
enemyDistance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if enemyDistance > 0 :
enemyDistance
# Say the value of enemyDistance variable.
hero.say("15")
I would appreciate your help once again!
You still haven’t done this.
I am sorry I am still confused wasn’t the hero.say
part so that the wizard would attack?
Would you mind explaining me what my problem is in another way?
Presently, the argument for the hero.say method is a string - “15”
You should be calling your enemyDistance variable as the argument.
Also, immediately after the if enemyDistance
conditional statement, you call your variable but for no reason. That line should not be there. It does nothing.
Munkey Shynes, when you say ‘calling your enemyDistance’ do you mean that my character should say that?
Calling = Saying?
Why don’t you try it and find out?
Hi @MunkeyShynes I tried hero.say enemyDistance
which is what you said (or at least I think so)
but the wizard says “say a number!” so I tried making a few tweaks to the code : still no result.Here is my actual code with the
hero.say enemyDistance
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10
if enemy:
result = hero.distanceTo(enemy)
return result
while True:
# Call nearestEnemyDistance() and save the result in the variable enemyDistance
enemyDistance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if enemyDistance > 0 :
# Say the value of enemyDistance variable.
hero.say("enemyDistance")
Honestly, I don’t know what to do
Take the quotes off enemyDistance.
@MunkeyShynes I figured out thank you so much I literally could not have done this without you.
once again thanks!
All default comments deleted - your code without changes:
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10 # you set the default distance to enemy to 10
if enemy: # and if there is no enemy
result = hero.distanceTo(enemy)
return result # the distance to enemy will be 10
# if there is no enemy
while True:
enemyDistance = nearestEnemyDistance()
if enemyDistance > 0: # this will be always true
# 10 or the real distance
hero.say(enemyDistance)
Question 1: is this line really needed?
result = 10 # or some other value
Can we comment it?
Question 2: Can we write only?:
if enemyDistance: # without comparing enemyDistance to 0?
i get it now thank you
that actually helped me alot thank you it took me 2 days to figure it out thanks for the advice
for some reason my wizard continuously attacks
here is my code`
type or paste code here
```def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10
if enemy:
result = hero.distanceTo(enemy)
return result
while True:
# Call nearestEnemyDistance() and save the result in the variable enemyDistance
enemyDistance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if enemyDistance > 0 :
# Say the value of enemyDistance variable.
hero.say(enemyDistance)
@dedreous @ducky @CodingGeek14
def nearestEnemyDistance():
enemy = hero.findNearestEnemy()
result = 10
if enemy:
result = hero.distanceTo(enemy)
return result
while True:
# Call nearestEnemyDistance() and save the result in the variable enemyDistance
enemyDistance = nearestEnemyDistance()
# If the enemyDistance is greater than 0:
if enemyDistance > 0 :
# Say the value of enemyDistance variable.
hero.say("enemyDistance")
The problem is with line 3 and 14. As written, line 3 will make enemyDIstance always > 0. What happens if there is no enemy…what is the value of result then?
Line 14, as written, is having the hero say a literal string value (which will always be “enemyDistance”), not the value of the variable…lose the quotation marks.
okay and could we talk in a dm