KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

Can't toggle actions, can only blindly set them true/false. #2197

Open Dunbaratu opened 6 years ago

Dunbaratu commented 6 years ago

Actions (the things that can be bound to action groups) have 3 things you can do with them in the VAB user interface:

Our PartModuleFields system can only do 1, or 2, but cannot do 3. There is no way to query the current value of the action on the partmodule, and no way to say that the desire is to toggle it.

While a script could track whether or not it has toggled the value before and could track its state, it can't detect if the user has manually flipped the value outside the script.

The realization of this deficiency comes from a Reddit post, so at least 1 user was trying to do this.

Dunbaratu commented 6 years ago

Wasn't sure if this was bug or enhancement since what it is, is correctly adhering to design, but the design was flawed.

Dunbaratu commented 6 years ago

Okay I'll remove "bug" because after searching I can't find a way in the API Squad provided that allows querying the information. This explains why this was never supported in the first place.

As near as I can tell, the ability to assign a "toggle" must depend on some boolean info that KSP is tracking somewhere entirely outside the PartModule itself (perhaps in the user interface code it's tracking what value it last assigned the action to, so it knows how to toggle it??).

A KSPAction can only be called with a hardcoded True or False passed into a Delegate method. The state can't be queried and isn't stored inside the PartModule. It has to be somewhere in the UI code that called the KSPAction which is a problem because that means toggling the state in script code is probably confusing the UI code into getting its own flag wrong. (I suspect KSP's UI code is operating under the assumption that it and only it can change the action's value, so it can track the state itself for toggling purposes.)