2

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?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
LWeaver
  • 45
  • 4

2 Answers2

1

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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
0

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 :(

user430788
  • 2,143
  • 2
  • 17
  • 17