0
if (time.clock() > 10: 
    DO SOMETHING

this only works with 1 iteration of the function then the time.clock surpasses 10seconds.

How do I do:

 if (time.clock > time.clock + 10):

how do I save a value for the clock at a particular instance??

I have already tried the get_time() function although this doesn't work on the account that python throws an attribute error

james jake
  • 39
  • 1
  • 8
  • Better use one of these solutions: [`pygame.time.get_ticks`, `pygame.time.set_timer` or the `delta time (dt)` variant)](https://stackoverflow.com/q/30720665/6220679). Also, `time.clock` is deprecated since Python 3.3. – skrx Oct 24 '17 at 07:19
  • Possible duplicate of [Countdown timer in Pygame](https://stackoverflow.com/questions/30720665/countdown-timer-in-pygame) – skrx Oct 24 '17 at 07:21

3 Answers3

3

You can save time.clock in a variable

first_instance = time.clock()
if (time.clock > first_instance + 10):
elanor
  • 172
  • 8
0

you could rather do

import time

time.sleep(10)
#do something.
Nae
  • 14,209
  • 7
  • 52
  • 79
0

You could also use the modulus operator

if(time.clock() % 10 == 0)
#do something

But this will make something happen after every 10th second, and also at the 0th second. But the benefit would be being able to change the behavior to work every 11th second for example which maybe would be preferable or every 12th second. For example every 15th second would be:

if(time.clock() % 15 == 0)
#do something 
Clive Makamara
  • 2,845
  • 16
  • 31