Exit command

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 :slight_smile:


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

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.

1 Like

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_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])
            SetWidgetValue(AMP_WIDGET[x], 0.0)

// Turn amp ON from midi controller
On ControlChangeEvent(m : ControlChangeMessage) Matching 35 from OMNI
    var index : Integer
    index = GetCCValue(m)

// Turn amp ON from widget
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from ACOUSTIC, RHYTHM, LEAD

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. :slight_smile:

Preferably, terminate a script to prevent it from misbehaving.

Exactly, a radio button. Will be watching for your example. :grinning:

Here you are! :slight_smile:
I hope this helps…

1 Like

Thank you! Checking it out now.

1 Like

Preferably code it right to prevent it from misbehaving :stuck_out_tongue_winking_eye: (I have to admit it is not the first time that I kill GP with one of my GPScript :innocent:)


This is the final script. Thanks to Schamass for his example!

	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
			AMP_LAST = 0

// 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

		AMP_LAST = index
		AMP_VALUE = index * 0.5
		SetParameter(ARCHETYPE, 18, AMP_VALUE)

    // Prevent a button to be switched off manually
    If newValue == 0.0 and index == AMP_LAST Then

I am happy to see that you got it running! :+1: :beers: