Is clock.schedule_interval() valid in pygame or only pygame zero?

Question:

I’m following a tutorial that involves pygame zero and adapting it to create a pygame program, but am haing issues with my timer. The time_left variable is set to 10 earlier, here is the rest of the code to do with the timer:

def update_time_left():
    global time_left

    if time_left:
        time_left = time_left - 1
    else:
        game_over()
    
clock.schedule_interval(update_time_left, 1.0) 

will the clock.schedule_interval() part work in pygame? And if not is there anything else I can use instead?

Asked By: LWeaver

||

Answers:

schedule_interval doesn’t exist in pygame. See pygame.time module. schedule_interval it is a method of the class Clock in pygame zero. See Pygame Zero – Built-in Objects.

In pygame you can create a timer event. See the answers to the question Python 3.8 pygame timer? or Countdown timer in Pygame.

Answered By: Rabbid76

The pygamezero docs lie. The second parameter in schedual_interval is in ms, not sec.

If you want a 1 sec delay, use 1000

I figured this out the hard way 🙁

Answered By: user430788
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.