Sending Selected Switch Number.. how?

Hi,

I have all my articulations from Logic auto loaded in a Switch grid.
I'm able to send the value assigned to each switches without issue.

I would also like to send the pressed switch number.
ex switch number 1, switch number 2, etc...

Is it a simple way to do that ?

On the OnValue script, something like

var PressedSwitchNumber = ?????

Thanks for your help !

It's not very clear to me what it is you want to send, is it the switch's number (as in: there are multiple switch widget and you want to know which one is interacted with) or the button's number within a switch (as in: the switch sends values that are not reflecting the actual selected position and you want to send that information as well) ?

Yes, this is it !
each buttons are able to send their correct assigned value, but I want to also send the actual button's number (Button 1, Button 2, 18, etc..)

1 Like

Then, in the switch's onValue:

var values = getProp(this, 'values')
var n

if (Array.isArray(values)) {
  // if values is written as an array (["a", "b"])
  n = values.indexOf(value)
} else {
  // if values is written as an object ({"label a": "a", "label b": "b"})
  n = Object.values(values).indexOf(value)
}

// now do something with n
console.log('value pressed n° ' + n)
send('/switch/n', n)

Thank you so much @jean-emmanuel
This is it !!!!!