A
atmobeat
Guest
I'm using an Input object that checks the hardware directly (among other things). My game is a zelda-like game with a focus on puzzles and has a mechanic or two that allow the player to control other characters, so I'm doing something a little different this time. After thinking about how to easily and clearly code such mechanics, I decided to have a variable called 'controlledInstance' initialized in my input manager object and then use a with-statement to perform user event 0 (reserved as a "Read Inputs" event in all objects my player can control).
I liked the idea for a few reasons: (i) it's not a huge deal but my input object checks the hardware in the begin step and the with-statement immediately has my controlled instance reacting to those inputs (kind of in-between the begin step and step events), so I can use the step and end step event for other things or even some more fine-grained ordering of things later if necessary; (ii) it's pretty clean as all the code for reading inputs is pretty decoupled from other things the object might be doing (especially nice for the enemies since their step event can focus on their normal AI state machine); and (iii) it's pretty straightforward for switching between objects (the code is only ever executed if that instance is actually the controlled instance, I don't need any checks for if my orc_warrior is controlled by the player character, and I don't need to introduce a truck-load of new states into their normal state machines). Maybe there are some other things I haven't thought about either.
After thinking about what is needed in my "Read Inputs" user event, it seems like I just need to put the entire state machine in there for those objects. This is because generally each state of the state machine reads the inputs in order to determine what state is next and then does other things associated with the state such as knowing when a state is being entered/exited, setting sprite indexes, playing sounds, etc. That seems natural, but my question (finally!) is this: is there some way to decouple the controls from the state machine and put them into my user event? Or better, is there some way to do that CLEANLY in a way that makes sense and isn't forced? Have any of you tried to do something like that? Is that kind of decoupling worth it?
I liked the idea for a few reasons: (i) it's not a huge deal but my input object checks the hardware in the begin step and the with-statement immediately has my controlled instance reacting to those inputs (kind of in-between the begin step and step events), so I can use the step and end step event for other things or even some more fine-grained ordering of things later if necessary; (ii) it's pretty clean as all the code for reading inputs is pretty decoupled from other things the object might be doing (especially nice for the enemies since their step event can focus on their normal AI state machine); and (iii) it's pretty straightforward for switching between objects (the code is only ever executed if that instance is actually the controlled instance, I don't need any checks for if my orc_warrior is controlled by the player character, and I don't need to introduce a truck-load of new states into their normal state machines). Maybe there are some other things I haven't thought about either.
After thinking about what is needed in my "Read Inputs" user event, it seems like I just need to put the entire state machine in there for those objects. This is because generally each state of the state machine reads the inputs in order to determine what state is next and then does other things associated with the state such as knowing when a state is being entered/exited, setting sprite indexes, playing sounds, etc. That seems natural, but my question (finally!) is this: is there some way to decouple the controls from the state machine and put them into my user event? Or better, is there some way to do that CLEANLY in a way that makes sense and isn't forced? Have any of you tried to do something like that? Is that kind of decoupling worth it?