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

[SOLVED] Python Blind Distance


#1

I’m trying to complete blind distance but i always run out of time because the wizard gets too tired too fast because he needlessly attacks when he doesn’t need too so i fail i have tried using stuff that isn’t involved in the level but no matter what it fails over and over its frustrating.


#2

Can you please post your code? :slight_smile:


#3

Mod edit: [Please do not post working code]


#4

Why would you command your hero to say("10")? Surely you defined the variable enemyDistance for a reason. Maybe for you need to say enemyDistance (hint :wink:)


#5

And of course now it works -_-


#6

What did you change to make it work?


#7

thx very much i solved it
been a great help
hope i enquire for more problems


#8

I want to know as well.
I am stuck on this level:yum:


#9

The 10 does not work for me why?


#10

If you want help with your code, please could you post it on the discourse (formatted as it states in the FAQ) and say what you’re having trouble with. Thanks :wink: (also I don’t think @innerdesert4346 is active any more)


#11

Thanks it worked and it is really helpfull


#12

Hello I don’t mean to revive this topic , but I didn’t want to create a new topic since it already existed. At first I had code errors but I fixed everything and I don’t have the little duck alerting me.
The problem now is that my code has no errors and it “runs”, I say it “runs” because my character doesn’t do anything. I don’t know if it is a mistake I made or it’s a bug.
Please help! my code is below.

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 hero.distanceTo > 0 : 
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

#13

In your while True loop, you’ve created a variable that you don’t use - enemyDistance. Your if statement should include this variable instead of the incomplete method that you currently have and this variable should be the argument in the hero.say method.


#14

so I should use enemyDistance in my of statement?


#15

@MunkeyShynes I guess not it gives the same result


#16

Those two changes should have worked. Did you do both of the suggested changes? Please post your code again.


#17

Because your hero is saying “nearestEnemyDistance()” or “enemyDistance”. These are the names of the function or of the variable and are strings, not actual value. These two hold the value of the distance.
a = 5
hero.say ( ‘a’) # output -> a
hero.say ( a ) # output -> 5

_TD_RodYT May '17
Why would you command your hero to say("10") ? Surely you defined the variable enemyDistance for a reason. Maybe for you need to say enemyDistance

    enemyDistance = nearestEnemyDistance()
    # If the enemyDistance is greater than 0:  
    if hero.distanceTo > 0 :  # see above: this line is wrong

#18
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 hero.distanceTo > 0 : 
        enemyDistance
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

first solution you suggested @MunkeyShynes


#19
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 hero.distanceTo > 0 : 
        enemyDistance = nearestEnemyDistance()
        # Say the value of enemyDistance variable.
        hero.say("nearestEnemyDistance()")

second one.
maybe it doesn’t work because I misunderstood your explanation?


#20

what? I don’t understand