Post by nic on May 3, 2019 18:50:47 GMT
This article concentrates on some of the more advanced/esoteric features of StreamByter.
Preserved Variables
Normally, when you assign a value to a variable, it will overwrite what is already there. However, in some cases, you might wish to retain the current value of that variable with the script's configuration.
Take a slider, for instance. Let's say you define it to store something the user will set, like a delay value:
set Q0 Delay $0 $2000
assign Q0 = 0
Each time, your script is loaded or installed, the slider will be reset to zero, and if the user had moved the slider, that value is lost. Enter 'Preserved Variables', which are a technique of preserving a variable's value over installs or preset loads. You mark a variable as preserved by setting the +PRESERVE flag in an assign rule:
set Q0 Delay $0 $2000
assign Q0 = 0 +preserve
Now, if the user moves the slider, then when 'Install Rules' is pressed, if there was already a value in that slider, the assign rule will not assign 0 but whatever the slider value was before Install was pressed. If there was no saved value, then it will assign the 0 as normal. So a preserved variable will 'fall back' to the default you assign in your script if there is no preserved value.
Here's where Preserved Variables come into their own. Say the user loads up your script and changes the delay slider and then saves their work into a new preset (either in StreamByter or from the AU host). When they go and load that script again, the slider will already be set to the position it was in when the script was saved.
You can also preserve values in the storage arrays (G, I, J, K, L, W, P), but it does not make sense to preserve timer, message or random values (T, M or R).
Note, only the specific array element is preserved (not the entire array).
Preserved Variables
Normally, when you assign a value to a variable, it will overwrite what is already there. However, in some cases, you might wish to retain the current value of that variable with the script's configuration.
Take a slider, for instance. Let's say you define it to store something the user will set, like a delay value:
set Q0 Delay $0 $2000
assign Q0 = 0
Each time, your script is loaded or installed, the slider will be reset to zero, and if the user had moved the slider, that value is lost. Enter 'Preserved Variables', which are a technique of preserving a variable's value over installs or preset loads. You mark a variable as preserved by setting the +PRESERVE flag in an assign rule:
set Q0 Delay $0 $2000
assign Q0 = 0 +preserve
Now, if the user moves the slider, then when 'Install Rules' is pressed, if there was already a value in that slider, the assign rule will not assign 0 but whatever the slider value was before Install was pressed. If there was no saved value, then it will assign the 0 as normal. So a preserved variable will 'fall back' to the default you assign in your script if there is no preserved value.
Here's where Preserved Variables come into their own. Say the user loads up your script and changes the delay slider and then saves their work into a new preset (either in StreamByter or from the AU host). When they go and load that script again, the slider will already be set to the position it was in when the script was saved.
You can also preserve values in the storage arrays (G, I, J, K, L, W, P), but it does not make sense to preserve timer, message or random values (T, M or R).
Note, only the specific array element is preserved (not the entire array).