Skip to content

Delayed onClick/onToggle after set button:pressed #2239

@ghost

Description

Wouldn't executing events/callbacks immediatelly (after changing state by kerboscript) be more understandable and usefull (e.g. for custom radio groups spread over multiple boxes)?

local wnd is gui(0).
local bt1 is wnd:addButton("TEST").
local bt2 is wnd:addButton("OTHER").
set bt1:toggle to true.
set bt2:toggle to true.
local counter is 0.
local function click {
	parameter me.
	parameter it.
	parameter on.
	if on set it:pressed to false.
	set counter to counter+1.
	print counter+"."+me:text+"="+on.
}
set bt1:onToggle to click@:bind(bt1,bt2).
set bt2:onToggle to click@:bind(bt2,bt1).
wnd:show().
wait until counter > 10.
wnd:dispose().

Output:

1.TEST=True
2.OTHER=True
3.TEST=False

Would require changing TriggerNextUpdate to CallPassingArgs, probably.
And btw, the code will crash until you accept #2238

https://ksp-kos.github.io/KOS/structures/gui.html#gui-callback-technique
will interrupt whatever else you are doing and call a function you wrote called myClickFunction whenever that button is clicked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions