Reading developers manual and forum’s examples of scripts I’m still struggling to understand the logic of how interaction between script and UI is provided. Say, I want it to be carried out only by the means of script (without typing-in addresses for parameters in Macro Page Designer). To my understanding I am to create a Parameter via defineParameter function. Let it be like this
defineParameter(mySwitch, nil, 0, 1, 1) (by the way what for Long Name is used?)
Now I can see the newly created parameter in the Parameters List and can read or change its value from the script via getParameter() and setParameter().
After it I create a button on Macro Page. Now how can I relay mySwitch value to the button’s state and vice verse – relaying button’s state to mySwitch? How can it be done with less of drag-n-dropping, but via script only?
You can’t. That’s how it works in Halion. But it also has some advantages. You can create a macro page without any scripting at all.
getParameter and setParameter are useful when you want to change Halion engine parameter from script. To change the value of script parameter simply assign new value to it.
mySwitch = 1
To get the value of script parameter simply refer to its name
One reason to use setParameter for script parameter is if you want to call its callback function (if it has one). This doesn’t happen when you change the value of script parameter by assigning new value.
But that’s inside script, how can I change mySwitch according to a button state on UI? Will the button send its state and thus change mySwitch if I create connection via drag-n-drop? I’ve tried it, but don’t see any change of mySwitch value.
My inquiry caused by a demand to hide\show and even move UI elements according to a certain values of variables used in the script. Is it achievable at all?
Well, what I meant is use a parameter instead of variable in your script. In fact parameters and global variables are treated the same in the script. The difference is the state of global variables is not saved with the preset and also cannot be accessed from outside the script.
So if you have a variable xy in your script, define parameter with the same name and you can use it the same way as you would be using the variable. If you use the variable to store a number, define numeric parameter…
Ok, no problem with using parameter instead of a variable. But I have issue now connecting parameter and UI element. Is it just a mere drag-n-drop to create a connection and have fully working pair “parameter - UI element”?
Ok, I’ve managed to connect an UI slider (with range from 0 to 127) and a parameter in the script, which defines a note number to play.
defineParameter("NoteSelector", nil, 0, 0, 127, 1)
local id = playNote(NoteSelector, event.velocity, -1, 1)
The only issue now is that every time I reload the script the NoteSelector gets its default value (which is 0) and lowers down the related slider on UI. Why the parameter is not stored as it must be persistent?
Ok - two types of reload arrows are good. But when I add a new version of the script in the editor it will also drop down all parameters to thier default values, which is a bit annoying, when building an instrument.
No,no - my main question is how a click on UI control can execute a function in Lua Script? For example I have connected a parameter in the script with a UI control (a button). Clicking the button changes the parameter. But how changing of a parameter can execute a certain function?