Scripting help: Menu value to change value in PreArgs of another widget

Hey all!

I'm trying to set up a menu that has multiple options that, when selected, will change the MIDI value sent on another button widget when the button is triggered. How do I write a script for these widgets to do this? Are variables involved?

Example to help explain:
I select "Menu item 1" in the menu widget, and the button widget's preArgs change to [3,1]. I select "Menu item 2" in the menu widget, and the button widget's preArgs change to [3,2]. And so on...

Idea 1: A script in the menu widget to change the MIDI value the button widget will send when triggered based on the selected menu item. But I don't know how to do this? VAR? Noob to JS, here.

Idea 2: A script in the button widget to assign a different MIDI value in the PreArgs to send when it sees that the menu has chosen a menu item.

Thanks in advance for any help you can provide.


I think the simplest way is to define the menu values prop as an object, where each value is the preArgs array to be used in the button, like so:

  "value1": [ 3, 1 ],
  "value2": [ 3, 2 ]

Then, in the button widget preArgs prop just use (considering the menu id as menu_1):

1 Like

So simple, so elegant. Thank you!!!

1 Like

@ClelsonLopes I've encountered a new issue here —

I've changed the Menu to automatically send the value for the button:

Now, I want to be able to have the button still be able to trigger the 'off' value, but it seems that whatever I did above nullified the @{"MenuID"} value we had placed in the preArgs:
Screen Shot 2022-05-16 at 5.42.28 PM

How might I achieve this such that it still accesses the correct value? I tried getProp, but it didn't work:
Screen Shot 2022-05-16 at 5.44.39 PM

(by the way, I recognize that the dropdown values are different, I just sent a screenshot from a different button to demonstrate)

Bonus question: How might I have it so that the button automatically is in the 'on' state when a new menu item is selected (without automatically stopping it)?

Thanks in advance! Learning my JS very slowly :blush:

It's not possible to compare equality of arrays like you did. In order to compare them, you need to stringify the arrays. join() is an option:

if (value.join() == [ 3, 1].join())

Try fixing this, and then test your idea again.

getProp only works in any scripting prop, like onValue, onCreate, etc
Check the docs Scripting - Open Stage Control

I'm quite confused of what you want to achieve, but my suggestion is to, instead of sending the MIDI messages from the menu, make the menu to set the button state. You get two of your desired results at once: button gets on and it sends the MIDI message.

So I believe I have a similar question on modifying properties based on another widget. In my case I have a toggle or push button. I would like it to change other buttons parameters and labels when its pressed.

How do I reference the "label" property of another widget in the onValue script?

You can use VAR{} inside a prop Advanced syntaxes - Open Stage Control, then get/change/ its value from a scripting prop using getVar() or setVar() Scripting - Open Stage Control

if (value ==1)
getProp('button_1', 'label')

get's the proper name but then how would I change this?

What if the toggle button is to change multiple other button labels when pressed? Would I have to make a separate VAR{} for each one?

Yes. They can have the same name, because they are scoped to the widgets id. If there are too many, instead of typing each line for each one, you can use some sort of for loop.

Awesome, thank you! I got it to work properly. Gotta look into for loops to shorten it a bit.

Good idea — how would I go about doing this? Something in Menu's "onValue" like:

VAR{menuState, @{this}};
getVar(dropdown_1, menuState);
setVar(button_1, menuState, @{this});

Obviously I don't know what I'm doing but maybe this is a start?

Hmm, not quite that. I meant something like this in the onValue prop of the menu:

const valueToString = value.join()
if (valueToString === [3, 1].join()) set("button_1", 1) //button name is "button_1" and its `on` value is 1

Thanks so much!

I've added the following to the menu:

const valueToString = value.join()
if (valueToString === [3, 1].join()) set("button_1", 1)

I don't know what parameters to change in the button to receive the different values assigned to each value:
Screen Shot 2022-05-16 at 7.32.10 PM

Is there a way to have the dynamic Value sent with each menu item as a part of this? I need to do some learning about 'const', 'valueToString', and 'join' because those are new to me.

I think what's unique here is that I want the button to still be able to send the 'Off' value to my DAW.

Hi, I am trying to utilize a for loop to rename buttons, but I can't get it to work. I keep getting an error would you happen to point me in the right direction / know what's wrong?

The following code is on the toggle button "on value". As you can see, the commented out code worked fine, but I have a lot more buttons to add so I wanted to use a loop instead.

I've renamed the button widget ID's to b_0, b_1, b_2 etc. so to line up the ID and array value with the counter.


if (value == 1) {
  for (let i = 0; i < updatedName.length; i++) {
    setVar('b_'[i], 'labelChange', updatedName[i]);
//setVar('button_3','labelChange', 'UPDATED');
//setVar('button_4','labelChange', 'UPDATED');

else {
  for (let k = 0; k < originalName.length; k++) {
    setVar('b_'[k], 'labelChange', originalName[k])
//setVar('button_3', 'labelChange', 'ACCENT C-1')
//setVar('button_4', 'labelChange', 'CRESCENDO C#-1')

Here's the error I'm getting, button_12 is the toggle button.

Got it to work. The syntax on setVar ID was incorrect. I needed a ${} to put the counter in and then the entire ID value needs to be a string with `` around.

1 Like

For learning purposes, could anyone show me or explain how to do the above but using a custom module instead?

So for example, having a button change a property of multiple other widgets (such as label).