Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

[SOLVED] Keeping Time Help Needed


Using this code, my hero just stands there and not do anything. What is wrong with this?

# Use your new skill to choose what to do: hero.time

while True:
    # If it's the first 10 seconds, attack.
    if hero.time < 10:
        if enemy:
            enemy = hero.findNearestEnemy
    # Else, if it's the first 35 seconds, collect coins.
    elif hero.time < 35:
        if coin:
            coin = hero.findNearestItem
            hero.moveXY(coin.pos.x, coin.pos.y)
    # After 35 seconds, attack again!


add () to the end of the 6th line of code and in the 12th line of code.


I tried it, same results.

  1. You have a conditional statement, if enemy, before you define the variable, enemy.
  2. You have a conditional statement, if coin, before you define the variable, coin.

You must define your variables first before using/calling them.


I mean like coin = hero.findNearestItem()


Also, check if the enemy exists after 35 seconds.


This worked. Thanks.