I'm making a game in python using pygame and some other libraries. I have the main menu as one python file, and when a player is selected, it starts the game file. If you choose to go back to the menu while playing the game, it starts the menu up again. However from the new menu I can't start/open the game file anymore it doesn't do anything at all. (after each time I open a file I close the previous one)
eg:
Menu-->playerSelect-->gameStartUp-->Menu-->playerSelect-->Break/crash.
so actual code this would be for the first file that is the menu name "FlappyBirdMAIN, "HappyBrid" is the name of the second game file.
if startGui == 2:
screen.blit(background, [0, 0])
import HappyBird
done=True
pygame.quit()
for the second file "happyBird" i have it open the menu connected to pressing down the "m" key:
if event.key == K_m:
pygame.mixer.fadeout(1)
import FlappybirdMAIN
done=True
so it import FlappyBirdMAIN then done=True closes the "HappyBird" file
i have figured out that by making copies of the same files("FlappyBirdMAIN", and "HappyBird") then making them import each other in series i can have the menu come up then go down again(more than once) but when i link it back to the origonal file it crash/breaks eg:
EX1:
FlappyBirdMAIN-->HappyBird-->FlappyBirdMAIN2-->HappyBird2-->FlappyBirdMAIN3-->HappyBird3
EX2:
FlappyBirdMAIN-->HappyBird-->FlappyBirdMAIN2-->HappyBird2-->FlappyBirdMAIN3-->HappyBird3-->FlappyBirdMAIN
The problem was using the import command. exec(open("HappyBird.py").read())
using import cuases python to think its is already open, as it is a smart import system. (or something along the lines of that).
Repeating Import Module - Python / Pygame
^the link to how i figured it out.
Thanks.