I have a menu widget that I am populating with an array of strings from a custom module, using a listener in the values box of the widget.
The listener is OSC{/scaleButtonSwitch/names}
and this populates the menu correctly in that it receives the strings from the custom module and adds them to the menu widget.
I need the menu however to return an integer as the args[0] value when an item is pressed so that I can use this integer in my custom module.
How do I do this?
You could define the values withs labels / values instead of a simple array:
receive('/scaleButtonSwitch/names', {
labels: ["a", "b", "c"],
values: [2, 5, 9]
})
or with a simple object if there are no duplicate labels:
receive('/scaleButtonSwitch/names', {
"a": 2,
"b": 5,
"c": 9
})
Or, since you're defining all this from your custom module you could keep a map to convert the strings to integers:
var menu_map = {
"a": 2,
"b": 5,
"c": 9
}
// populate menu
receive('/scaleButtonSwitch/names', Object.values(menu_map))
// when needed (in oscOutFilter presumably), retrieve associated value
var numeric_value = menu_map[args[0]]