onValue javascript error at line 1: TypeError: value.match is not a function

Hi there!

I am getting an error in the console that is doubtless because I am doing something silly, but basically I 'borrowed' a bit of code from another post to capture the label of a switch (and used it in the 'value' entry of a variable). It was all working to plan til I noticed the console flash up this error whenever it received a new switch value:

'KK1FXNameVariable.onValue javascript error at line 1: TypeError: value.match is not a function'

The actual JS I have in the 'value' field of the variable (that does seem to return the label of the switch position!) is this:


var values = @{KK@{parent.variables.a}DynPostFader.values},
v = @{KK@{parent.variables.a}DynPostFader}

return Object.keys(values).find(k => values[k] == v)


Sorry to be a pain but have no idea what the error message means!

Any assistance greatly appreciated thanks!

Edit - Actually, I think I have managed to play around a bit with project and fix this, seems it didn't like a label with a value of '1 ', '2 ' etc, but when I changed this to '1. ', '2. ' etc the console stopped displaying the error (still don't understand what was going on but happy the error has gone! :grin: )

When writing


one assumes the variable value is a string, this will produce an error with any other type of variable. When widget properties are resolved, open stage control attempts to guess the type without making assumptions on what's expected in a particular property (e.g. label may in fact be a string, a number, a boolean...). In this case it's interpreted as a number, hence the error, which you can avoid by coercing the variable to a string before calling match:

1 Like

Thanks for explaining this Jean-Emmanuel, makes perfect sense now (explains why what I tried solved error!), first class support as always! :+1: