[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
            hero.attack(enemy)
            pass
    # 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)
        pass
    # After 35 seconds, attack again!
    else:
        hero.attack(enemy)
        pass

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.

1 Like

I mean like coin = hero.findNearestItem()

Also, check if the enemy exists after 35 seconds.

This worked. Thanks.

this is the wrong code can you help me.

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
hero.attack(enemy)
pass
# 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)
pass
# After 35 seconds, attack again!
else:
hero.attack(enemy)
pass

Could you please post your code correctly as it says in this
Lydia

can you please help me solve this code in javascipt.
// Night is coming! Move all the soldiers towards the fire.
function centerFormation(event) {
// event.target is the unit running this event handler.
var unit = event.target;
// Now use unit.moveXY to move the unit to the fire.

}

// This spawns the four soldiers:
game.spawnXY(“soldier”, 16, 57);
game.spawnXY(“soldier”, 15, 13);
game.spawnXY(“soldier”, 63, 13);
game.spawnXY(“soldier”, 67, 57);

// This sets the soldier’s spawn action to the function centerFormation:
game.setActionFor(“soldier”, “spawn”, centerFormation);

Please post your code formatted correctly.
Lydia