Convert string to widget type?

Hi,

I am trying to access a widget by first defining its scriptname as a string. Is this possible?
Here’s what I’m trying to achieve.

Let’s assume I have multiple widgets with a scriptname that has a common part (e.g., “knob_”), followed by a number. Let’s assume there are four of those: knob_1, knob_2, knob_3 and knob_4. (In my application I have up to 32, though.)

Depending on certain parameters, I then would like to define which widget needs to be addressed by concatenating the common part with its number. So, something like widget_name = "knob_" + knob_number.

Using this string variable to call the widget
SetWidgetValue(widget_name, newValue)
does not seem to work, I guess because it expects a type widget instead of a string as first variable.

Is there a way to convert the string into the widget’s scriptname, like StringToWidget() or something equivalent?

Thanks!

If you really need this kind of processing, the only way is to put the knob-widgets in an array of widgets. Then you can use the knob-number as index to that array.

What you tried (at runtime creating a string and use that like a widget) is not possible.

No. In GPScript, a widget’s “scriptname” is actually a legitimate variable that you declare, it’s not just another string.

Despite the name, GPScript actually compiles your code and internally, that widget variable is a real native pointer to the widget itself

This an example what you can do at runtime using an array:

RuntimeWidgetSelect.gig (76.2 KB)

It is a rather crude version, and maybe not exactly what you want, but it gives some pointers on how to use a widget array

Thank you for your feedback, and apologies for the late response (I was traveling).

I already assumed this would not be as simple as I’d wished, so I will definitely look into the approach using arrays in more detail…

Just wanted to inform you I successfully implemented what I wanted to do using the arrays. Thanks for the guidance.

Here’s an extra question.

I was wondering what the impact is of defining widgets and arrays of widgets in a script that are not present (anymore) in a rackspace.
I know warnings appear in the log window, but does this actually impact the performance or stability in any way? Or is it still ‘safe’ to do this?

The scenario would be as follows.
I am creating a larger template, that includes all the knobs and buttons, and related scripts, for up to 8 sounds (could be more in the future).
If I then create a copy from this rackspace with, say, only 2 sounds, I would delete the panels for the unused extra 6 sounds, effectively removing the knobs and buttons with scriptnames that are referenced from the template’s rackspace script. Now the warnings will appear when activating the rackspace, but everything still seems to work, as far as I can see.

So, how risky is this? Or should I really clean up my script when done (as I have been doing up to now) to be 100% safe?

The script will not compile anymore and maybe you face a runtime error.

At best you will get a runtime error. At worst, you will crash Gig Performer.

Don’t do that :slight_smile:

1 Like