Jump to content

Survey: How do you program your "Toggle" actions in your plug-ins?


Recommended Posts

In my development of Action Groups Extended (which adds more action groups to KSP), and in the work I'm doing with other mods in order to integrate with them, I'm starting to notice two distinct methods of how to handle "Toggle" actions.

As I'm providing ways to activate these actions the community is creating, I'm feeling out the waters on what is going on.

Note this is not a "you are doing it wrong" thread, or an attempt to standardize or anything. I just need to know how you guys are programming your actions so I can handle them correctly in my mods.

The two methods I'm seeing are as follows:

1) Activate is turn on, Deactivate is turn off:

This is how stock partModules work.

The KSPAction(ActionParam) method on every action is passed the ActionParam variable as an Activate or Deactivate command.

The code behind the toggle action then checks this ActionParam and Activates or Deactivates as appropriate.

This is why you see things such as the first press of the G (gear) key doing nothing when you launch a vessel with stock landing legs already extended. The landing legs are already extended (activated), but the Gear group starts deactivated. Then when you toggle the Gear group with G, you are passing KSP the ToggleGear(Activate) command, but because the landing legs are already extended, nothing happens.

2) Toggle means toggle, ignore the ActionParam activate/deactivate.

I'm seeing several mods use this. Rather then check the ActionParam to see if they should activate/deactivate, they are checking their own variable.

For instance, in the landing leg example above with the landing legs already extended (activated).

The Gear group is still deactivated on flight start, however when the player presses the G key and KSP passes the modded landing leg the ToggleGear(Activate) action, the landing leg checks its own state instead of the passed ActionParam, sees it is already extended and retracts (deactivates) as opposed to the ActionParam activate that it was passed.

Now, in my opinion both methods have their advantages, but supporting both methods does make the work on the mods I'm doing more complex so I wanted to get the opinions of the people making the mods (and actions) I have to work with to see what they thought.

Also, I'm doing this to check if there is a third method to handling the Toggle action that I've missed that I need to support.

So, what are peoples thoughts on this?

D.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...