Jump to content

Call and event when a slider is changed


Recommended Posts

Hello, I'm a long time game plugin developer but I'm working on my first KSP Plugin. I'm trying to figure out the tweakables system and I've seen threads here that have explained most of it. What I'm trying to do is immediately react when a slider is changed but I'm not sure how to link a KSPField to a KSPEvent. I've seen plenty of examples of having it automatically change a variable, which would be fine if I knew the variable had been changed. Is it possible to do this? An example of what I'm trying to do would be like moving the thrust limiter while in flight, the engine immediately reacts.

Link to comment
Share on other sites

I'm not aware of any callback or event that is triggered when that happens so here is how I would approach it.


[KSPField]
float currentValue;

float lastValue;

public void Update()
{
if(currentValue != lastValue)
{
print("Value changed!");
lastValue = currentValue;
}
}

This is pseudo code, syntax needs checking.

Note that this method will trigger multiple times as the player moves the slider as Update() is called multiple times a second.

D.

Link to comment
Share on other sites

Ok, I can filter multiple updates easy enough for what I'm doing. I didn't even see the OnUpdate method there hiding at the bottom of the documentation, so that will be good to know. I'll give that a try. Thanks!

Link to comment
Share on other sites

Maybe try using kerbal.InVessl() and if the vessel is null assume he is EVA? (I'm spitballing, I don't know if that works the way it looks like it does).

I don't think you can do the sliders dynamically unless Squad puts it in the attribute. I could use that so that the sliders do nothing while your in the vessel, but they would still be there and I think that would just be confusing. I think it would be better to just abandon attempting to do it EVA only and hope Squad adds the capability later.

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...