Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Python Blind Distance

#21

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.

3 Likes
#22

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.

#23

@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!

#24

You still haven’t done this.

#25

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?

#26

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.

#27

Munkey Shynes, when you say ‘calling your enemyDistance’ do you mean that my character should say that?
Calling = Saying?

#28

Why don’t you try it and find out? :grinning:

#29

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.:disappointed_relieved: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

#30

Take the quotes off enemyDistance.

2 Likes
#32

@MunkeyShynes I figured out thank you so much I literally could not have done this without you.
once again thanks!

1 Like
#33

is some what worked for me but i died here is the imaje

#35

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?
#36

i get it now thank you