Search code examples
pythonpygamemenureturnglobal-variables

Change game attribute from pygame-menu selector onreturn


I'm creating a menu selector using pygame-menus, as explained here. However, the onreturn value can only call a function, whereas I want to change the variable that defines the game mode. How can I use onreturn to change this variable without declaring a global variable within the called function?


Solution

  • Since instance attributes are global, I can simply use a function to change an instance attribute rather than a variable. That way, I need not use a global variable within a function. Changing values in a dictionary also works.