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