Is there a command or function to exit a Rackspace script?
Are you talking about an early exit from a function or callback?
If so, no there isnât. Goto statements are banned in GPScript
Not sure we all understand your question the same wayâŚ
When compiled, a GPScript runs forever, no way to stop it. But, in the script itself you can use widget states to enable or disable the action done within callbacks.
Perhaps you could expose what you would like to do exactly?
I believe he is talking about the use of an exit statement to return from a function (or from a callback) early. E.g,
Function foo(i : integer)
if i > 100
then exit // Return from the function
else ....do something
End
I understood he wants to exit a Rackspace script, and interpreted it as stopping the script.
Not sure what it actually means to âstop the scriptâ. The scrip is reacting to outside events or to a timer. One can stop a timer or stop responding to outside events if a flag is set for example.
The concept of âexiting the scriptâ doesnât really make much sense. The script is either there or not there.
If a GP script has to be âstoppedâ, you definitely did something wrong⌠i.e. created an endless loop, forgot to âcatchâ a certain situation, or something like that.
Thank you for the responses. To clarify, I was looking for a command that would exit the current execution of the script.
I wrote a script that would turn ON one of three LED widgets either by CC from a Midi controller or clicking one of the LED widgets in the UI. The problem is the script gets caught in an endless loop when one of the LED widgets is changed.
Here is the script:
var OMNI : MidiInBlock
ARCHETYPE : PluginBlock
ARCH_PARAM : Integer = 18
ACOUSTIC : Widget
RHYTHM : Widget
LEAD : Widget
AMP_WIDGET : Widget Array = [ACOUSTIC, RHYTHM, LEAD]
AMP_VALUE : Double Array = [0.0, 63.0, 127.0]
// Turn amp widgets ON/OFF
Function SelectAmp(ampIndex : integer)
var x : Integer
for x = 0; x < Size(AMP_WIDGET); x = x + 1 do
if x == ampIndex then
SetWidgetValue(AMP_WIDGET[x], 1.0)
SetParameter(ARCHETYPE, ARCH_PARAM, AMP_VALUE[x])
else
SetWidgetValue(AMP_WIDGET[x], 0.0)
end
end
End
// Turn amp ON from midi controller
On ControlChangeEvent(m : ControlChangeMessage) Matching 35 from OMNI
var index : Integer
index = GetCCValue(m)
SelectAmp(index)
End
// Turn amp ON from widget
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from ACOUSTIC, RHYTHM, LEAD
SelectAmp(index)
End
Oh, youâre looking for a way to terminate a script that is misbehaving.
Thatâs the unfamous âradio buttonâ behaviour (a sort of widgets that isnât yet supported by GP natively)⌠there are several user scripts/rackspaces available where you can see how this problem can be solved with GP script. Searching for those âmagic wordsâ will get you many threads in the forums⌠but it might be difficult to find a quick solution.
I guess, i will have to upload a proper example in the âuser scriptsâ sub forum, so that anyone can easily find it. Have some patience for that.
Preferably, terminate a script to prevent it from misbehaving.
Exactly, a radio button. Will be watching for your example.
Here you are!
I hope this helpsâŚ
Thank you! Checking it out now.
Preferably code it right to prevent it from misbehaving (I have to admit it is not the first time that I kill GP with one of my GPScript )
This is the final script. Thanks to Schamass for his example!
var
ARCHETYPE : PluginBlock
ACOUSTIC, RHYTHM, LEAD : Widget // Used button names
AMP_LAST : Integer // Buffer variables to store the last pressed button
AMP_ARRAY : Widget Array = [ACOUSTIC, RHYTHM, LEAD] // Declaration of widget arrays for buttons
Initialization // Called on first run
var i : Integer
// Check & store state of buttons - if all off, assume the first as "ON"
For i = 0; i < Size(AMP_ARRAY); i = i + 1 Do
If GetWidgetValue(AMP_ARRAY[i]) == 1.0 Then
AMP_LAST = i
Else
AMP_LAST = 0
End
End
End
// Called when any of several widgets changed
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from ACOUSTIC, RHYTHM, LEAD
var i : integer
AMP_VALUE : double
if newValue == 1.0 and index <> AMP_LAST then
// Deselect other buttons
for i = 0; i < Size(AMP_ARRAY); i = i + 1 do
if i <> index then SetWidgetValue(AMP_ARRAY[i],0.0) end
end
AMP_LAST = index
AMP_VALUE = index * 0.5
SetParameter(ARCHETYPE, 18, AMP_VALUE)
end
// Prevent a button to be switched off manually
If newValue == 0.0 and index == AMP_LAST Then
SetWidgetValue(AMP_ARRAY[index],1.0)
End
End
I am happy to see that you got it running!