[Solved] Keeping Time

help!!!
ive been working on “keeping time” for over an hour and till cant get it plz help me

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

enemy = hero.findNearestEnemy()
coin = hero.findNearestItem()

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

        hero.attack(enemy)
    pass
1 Like

the variables are supposed to be inside the while loop

1 Like

Please read this guide before your posting code:

1 Like

like this?

while True:
enemy = hero.findNearestEnemy()
coin = hero.findNearestItem()
# 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:
hero.moveXY(coin.pos.x, coin.pos.y)
pass
# After 35 seconds, attack again!
else:
if enemy:

        hero.attack(enemy)
    pass
1 Like

No, not like that. Please read the directions. It’s very simple to do correctly. If you do it wrong, it looks like what you posted. If you do it correctly, it should look like this:

while True:
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    # 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:
            hero.moveXY(coin.pos.x, coin.pos.y)
        pass
    # After 35 seconds, attack again!
    else:
        if enemy:
            
            hero.attack(enemy)
        pass

1 Like

so like this.


while True:
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    # 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:
            hero.moveXY(coin.pos.x, coin.pos.y)
        pass
    # After 35 seconds, attack again!
    else:
        if enemy:
            
            hero.attack(enemy)
        pass

1 Like

Yes just like that @ducky

1 Like

hero.findNearestEnemy needs “()” after it

1 Like

but it already has a “()” after it

1 Like

uh no? look inside your hero.time < 10 if loop

3 Likes

It doesn’t. the second one in the if eemy statement doesn’t have one

1 Like

@ducky does it work now?

1 Like

thx SO much!!! it worked.

1 Like

no problemo, senorita.

1 Like

It should be if hero.time<=10, the thing you did will make you attack enemy in the first 9 sec, but maybe the enemies are spawned so you have time to destroy them :stuck_out_tongue:

1 Like

@xantar it makes no difference in the current context.

“the thing you did will make you attack enemy in the first 9 sec”. That’s false.

If it’s 9.9999999seconds, then the hero will still attack the enemy.

It makes no difference since there is only one instant where hero.time = 10 on the dot, exactly.

So by writing hero.time < 10 you only lose (1 / framerate) seconds worth of attacking the enemy. (if framerate = 60, then you lose 0.01 seconds) However that doesn’t really matter since the hero can only attack 4 times every second with the fastest sword available.

1 Like

btw the OP’s problem has already been solved.

1 Like

I thought the framerate is 1, thx for telling me

1 Like

You can check the framerate of a level by clicking on Systems then going down the list to the existence button. Press that to see the framerate.

2 Likes

The default framerate for levels is 30 FPS.

1 Like