Thank you. I added the 'make persistent' lines. On reload, the button colour (it turns white when it's "on") is remembered now, but it's not having an effect.
See attached screenshot with my added lines.
Ideas?
Have you applied read_persistent_var() ?
From the Kontakt 5 KSP reference manual:
"
read_persistent_var(<variable>)
instantly reloads the value of a variable that was saved via the make_persistent() command
Remarks
• This command can only be used within the init callback.
• The state of the variable is saved not only with the patch (or multi or host chunk), but also when a script is saved as a KONTAKT preset (.nkp file).
• When replacing script code by copy and replacing the text, the values of persistent variables is also retained.
• Sometimes, when working on more complex scripts, you'll want to "flush" the variables by resetting the script. You can do this by applying an empty script in the respective slot.
• You can also use the on persistence callback for retrieving the values of persistent variables
"
Examples
Code:
on init
declare ui_label $label (1,1)
declare ui_button $button
set_text($button,"$a := 10000")
declare $a
make_persistent($a)
{read_persistent_var($a)}
set_text ($label,$a)
end on
on ui_control ($button)
$a := 10000
set_text($label,$a)
end on
"after applying this script, click on the button and then save and close the NKI. After reloading it, the label will display 0 because the value of $a is initialized at the very end of the init callback. Now remove the {} around read_persistent_var and apply the script again. Voila."