Array values from a script

Hi,

I'm trying to simply get data from an array by gathering a number received from a midi channel (widget called Received in this case).
I would like to make all of my buttons read a specific value from the grid (gridValue.1 read first value, gridValue.12, the 12th value, etc.)

var selector = @{Received.value}
var config = [{
'name': 'Violins 1',
'grid': ['1', '1', '1', '1', '0', '0', '1', '1', '0', '0', '0', '1', '1']
},
{
'name': 'Violins 2',
'grid': ['1', '1', '1', '1', '0', '0', '1', '1', '0', '0', '0', '1', '1']
},
{
'name': 'Violas',
'grid': ['1', '1', '1', '1', '0', '0', '1', '1', '0', '0', '0', '1', '1']
},
{
'name': 'Cello',
'grid': ['1', '1', '1', '1', '0', '0', '1', '1', '0', '0', '0', '1', '1']
}
]

var artNumber = config[selector]['grid'].length;
var artValue = config[selector]['grid'];
var name = config[selector]['name'];

then to have something like that to display the button:

#{
@{SCRIPTNAME.artValue.1} == 1 ? "display:flex;" : "display:none;"
}
}

Usually this is something I could easy do with Angular but nothing works here.
What I've done wrong? I'm pretty sure I have difficulties to unterstand OSC logic.

@{SCRIPTNAME} does not return the script’s context, it doesn’t return anything actually, if you want to use the script to assign a variable that can be reused somewhere else, store it in the global variable.

JS{{
global.artValue = 1; // etc
}}

Note that MathJs formulas (#{}) don’t have access to this object, so you’d need to write your second snippet as follow:

JS{{return global.artValue == 1 ?  "display:flex;" : "display:none;"}}
  • be careful, you’re using invalid double quotes
  • you should replace "display:flex;" with an empty string if you only intend to hide the widget when the condition is not met.
1 Like

Okay, makes sense now. I will try that! Thanks!

I’ve ended with an external javascript file. It was way easier to store that much data. It does work perfectly! (I used a bit of another user’s code.)

hi,

To make a community, it would be kind to share with others to have some code to read as examples in real life :slight_smile:
Is it possible to publish your code ?
Cheers

It’s a bit too long to explain and showcase the code here. It would needs its very own tutorial step by step to explain each part of the code and make it clear to everyone. I don’t have such time for that right now. However, I invite you to check what the original user did.
To do so, go to https://openstagecontrol.ammd.net/docs/examples/. At the bottom of the page, you will see my template picture plus a link to a tutorial I’ve made a year ago (for the community…) You will find original files there (and some serious discussion about it).

I don’t own the original code, I must redirect you to it and not upload it on my own. (but I’m thinking to do that later, if everyone involved are okay)

Okay perfect ! Thanks for sharing. I did not think to look at the examples area