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)