[Solved] Keeping Time


#1

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

#2

the variables are supposed to be inside the while loop


#3

Please read this guide before your posting code:


#4

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

#5

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


#7

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


#8

Yes just like that @ducky


#10

hero.findNearestEnemy needs “()” after it


#11

but it already has a “()” after it


#12

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


#13

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


#14

@ducky does it work now?


#15

thx SO much!!! it worked.


#16

no problemo, senorita.


#17

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:


#18

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


#19

btw the OP’s problem has already been solved.


#20

I thought the framerate is 1, thx for telling me


#21

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.


#22

The default framerate for levels is 30 FPS.