0

I have been working on pygame project based on thenewboston tutorials. It is an older series, I have got some errors while packing game loop into function (it references variables that are not global, if you use direction = "right", gameloop() gonna complain about unreferenced variable key = left: direction = "left"), so I decided to leave while loop as it is. My structure is:

while game['intro']:
...
while not game['exit']
...
while game['victory_screen']
message("press R to return to Main Menu")
if key = R: #simplifeid pygame.keydown, k_r.
  game['intro'] = True
  game['victory_screen'] = False

So instead of returning to intro, game just closes. I get why it is, python sees the end of the code and does not return to previous while loop. Any way to restart the game without closing it? I tired again to use functions, packing intro loop works, main game does not work, looks like functions don't really like while loops inside.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Blandon 93
  • 27
  • 2
  • "it references variables that are not global, if you use direction = "right"" Shouldn't have to do with the serie being old, but more of a misunderstanding of how python works Also while loop do work inside function, if you could show us what you tried may help us helping you – Sparkling Marcel Jun 02 '23 at 05:50
  • 2
    What you presented is not valid Python code. Indentation is wrong, colons are missing... Please provide valid code which can be run and which reproduces the issue. – trincot Jun 02 '23 at 06:16
  • https://youtu.be/juRZLrUkDtU here is the place where I encountered the error. used pycharm btw. – Blandon 93 Jun 02 '23 at 10:41

0 Answers0