0

In my pygame game, there is a time system. Every 5 irl min is one hour in game. I have my code for the time in a while loop that doesn't end. However whenever I run the function it is in, pygame just freezes and stops working completely. Here's the code

  gameExit = False
  while not gameExit:    
      sys.stdout.flush()
      time.sleep(300)
      sys.stdout.flush()
      game_time = game_time + 100
      if game_time == 2400:
          day = day + 1
          game_time = 0000

I think the problem is because the while loop never ends and Pygame doesn't seem to like that too much, so how would I make it where the time updates every 5 min but my game won't freeze

Thanks in advance, Shade

shadeyg56
  • 74
  • 4
  • 4
    When does `gameExit` ever equal `True`? – pstatix Dec 24 '17 at 02:43
  • never atm. It's just something to keep the loop going. I just saw that in the original tutorial I saw, and just never changed it or used it. I suppose I could just use `while 1 == 1:` – shadeyg56 Dec 24 '17 at 02:50
  • can you show enough of the code that we can reproduce the behaviour? – Azsgy Dec 24 '17 at 02:52
  • Atsch, I don't understand what you mean, sorry. – shadeyg56 Dec 24 '17 at 02:53
  • The game is freezing because you are calling `time.sleep(300)` in a `while` that is never ending. What do you think would be happening? Only this block of code can run (unless this in on another thread) and thus the game will freeze. – pstatix Dec 24 '17 at 02:58
  • pstatix, yes I understand. I need a way to resolve this while still having the time update – shadeyg56 Dec 24 '17 at 03:10
  • PyGame's examples: [time-control-object](https://github.com/furas/python-examples/tree/master/pygame/time-control-object) and [time-execute-function](https://github.com/furas/python-examples/tree/master/pygame/time-execute-function) – furas Dec 24 '17 at 04:28
  • Hey I ended up fixing the problem, sorry for wasting yalls time :D – shadeyg56 Dec 24 '17 at 04:43

0 Answers0