Copy Widget Value to Variable

How can I pass the GetWidgetValue script result to a variable?

I would like to take the current value of a widget called “mh1” and copy it to several others with the press of a button.

On WidgetValueChanged (newValue: double) from button_1
if newValue ==1
then SetWidgetValue (mh2, //variable holding current value of mh1//)
end
end

On WidgetValueChanged (newValue: double) from button_1
if newValue ==1
then SetWidgetValue (mh2,GetWidgetValue(mh1))
end
end

Great! Thank you Paul. Is there a shorthand version to setting this value to multiple widgets (mh2, mh3, mh4, etc.), or does each one require its own SetWidgetValue statement?

You can define a widget array and set the values in a loop.
But each widget has to be set separately.
You know widget groups?

Hi Paul yes I’m familiar with widget groups. I’m just looking for a bit more flexibility. Would you mind composing a short example script with the looping SetWidgetValue?

Sorry for the delay, here is an example gig:
Button_Set_Widgets.gig (8.1 KB)

And this is the script:

var button_1 : Widget
    mh1      : Widget
    mh2      : Widget
    mh3      : Widget
    mh4      : Widget
    mh       : Widget Array
    i        : Integer
    wv       : double
    
initialization
 mh = [mh1, mh2, mh3, mh4]
end 
    
// Called when a widget value has changed
On WidgetValueChanged(newValue : double) from button_1
 if newValue == 1.0 then
  wv := GetWidgetValue(mh1)
  
  For i=0; i < Size(mh); i = i+1 Do
   SetWidgetValue(mh[i], wv)
  End
 End 
End
1 Like

I think you can assign that mh widget array directly during initialization

Help me, what assignment?

This is great Paul. Thank you for your assistance. I’ll play with this.

var button_1 : Widget
    mh1      : Widget
    mh2      : Widget
    mh3      : Widget
    mh4      : Widget
    mh       : Widget Array = [mh1, mh2, mh3, mh4]
    i        : Integer
    wv       : double

No initialization section needed

1 Like

For sure we can :stuck_out_tongue_winking_eye:

1 Like