What I do is I create variables that I use to track the status of things like landing gear. I initialize them when they are in a known state. For example, when you're docked you know the gear is down, lights are off, scoops and weapons retracted.
I usually use boolean variables to keep track of these things since they only have two states: either on or off (true or false). When I perform an action like retract gear, I set the state of the variable to false. It works reasonably well.