I have a pygame game and im trying to get different menu "instances?" working So i start the game and it opens a main menu , i press play and it opens another instance which is game difficulty select, and then play again to go to the actual game All of the instances going forward from the main menu works, but i cant get a back button working, it just crashes.
My loops are built like this:
#State manager
menu = True
difficulty_menu = False
options_menu = False
maingame = False
# MAIN MENU LOOP
while menu:
clock.tick(fps)
#drawing menu
mainmenu_bg()
if play_button.draw():
menu = False
difficulty_menu = True
if options_button.draw():
menu = False
options_menu = True
if quit_button.draw():
menu = False
while difficulty_menu:
clock.tick(fps)
#drawing difficulty select screen
difficulty_bg()
and so on with the other instances. I start the main menu loop as true, clicking a button makes that loop false and makes the clicked loop true so i go to the loop i clicked into. And again, this all works
The problem is i tried making a back button for example in the options menu, so i tried this:
while options_menu:
clock.tick(fps)
#drawing options menu
optionsmenu_bg()
if back_button.draw():
print("test")
#menu = True
#options_menu = False
And doing this, makes the game crash
I tried making a back button:
if back_button.draw():
print("test")
#menu = True
#options_menu = False
but clicking on the button crashes the game, whilst the same codes going "forward" in menus work perfectly.