Hello, I'm in the process of making a game and after adding some menus and states player can be in I have started to face a problem of managing turning and turning off access to many states in which player can be (for an example you turn on inventory so you can't move, can't open other menus ect.). My solution to this was making a parent class with many start and end functions but its getting kinda ridiculus now and i wonder if there is a better solution to managing something like this. Would be glad to hear any solutions.

Pic rel.

One solution is to use a decision table. https://en.wikipedia.org/wiki/Decision_table Each possible combination of the variable values is assigned a state value, which is mapped to one or more actions. Then you can remove the individual variables, and use one state variable.

I did something similar, my solution was to make a manager function that takes in dictionary with values corresponding to a certain key that describes the variable. It's way more tidy than it was and it's easier to see any bugs

var possibleStates=7 func state_manager(Name,enterDict): if enterDict.keys().size()!=possibleStates: print("!Invalid dict size in function: ",Name,"!" ) for key in enterDict: if typeof(enterDict[key])==TYPE_BOOL: match key: "Movement": Movement.canMove=enterDict[key] "Inventory": Inventory.canUseInventory=enterDict[key] "Fight": Fight.canFight=enterDict[key] "Interaction": Interaction.canInteract=enterDict[key] "Menu": Menu.canMenu=enterDict[key] "ItemMenu": ItemMenu.itemMenuActive=enterDict[key] "Stats": Stats.can_open_stat=enterDict[key] _: print("!Invalid variable: ",key," in ",Name,"!")

And an example of a function called when starting/ending a state

func statMenu_start(): var enterDict={ "Movement":false,"Inventory":false,"Fight":false,"Interaction":false ,"Menu":false,"ItemMenu":"N/A","Stats":"N/A"} state_manager("statMenu_s",enterDict)
a year later