It sounds like you aren't using a class, but it should work anyway. Let's say you are using a match statement to call functions in a process function. In one of those functions you have another match statement that calls more functions along with the code to do whatever it is supposed to do. So it does something, then it checks the variable and does something else according to where the match statement sends it. So you would keep basically two sets of variables or enums. One for the main state, and one for the sub state. They would both be declared at the top of the script, so you could change them anywhere on the script. The main match statement would check one set, the sub match statement in the function, would check the sub enum or variable list. Hopefully you are at least calling functions with the match statement right now or else it would probably be too big of a mess.