How to use parent variables in a switch?

I was trying this sort of thing in 'values' but it just breaks:

{
  @{parent.variables}TypeA: 1,
  "B": 2,
  "C": 3,
  "D": 4,
  "E": 5,
  "F": 6
}

You are not giving us a lot to go on here @BillTribble. What are your parent.variables? I'm assuming that you're trying to pluck out just one and map it into a single switch key but there's not enough in your post for me to offer any advice.

OSC is a bit picky with advanced syntaxes in keys, for now the reliable way to go would be (assuming @{parent.variables} returns a string)

JS{
var values = {}

values[@{parent.variables} + "TypeA"] = 1
values["B"] = 2
values["C"] = 3
values["D"] = 4
values["E"] = 5
values["F"] = 6

return values
}

Ahh thanks JE! Format needed was a bit different? Experimentation revealed this:

JS{
var values = {}

values[@{parent.variables.LabelFoundA}] = 1
values["B"] = 2
values["C"] = 3
values["D"] = 4
values["E"] = 5
values["F"] = 6

return values
}

Now I just have the problem that some of the switches are showing in the wrong place!

'Off' should be first in the list (it's LabelFoundA)

JS{
var values = {}

values[@{parent.variables.LabelFoundA}] = 1
values[@{parent.variables.LabelFoundB}] = 2
values[@{parent.variables.LabelFoundC}] = 3
values[@{parent.variables.LabelFoundD}] = 4
values[@{parent.variables.LabelFoundE}] = 5
values[@{parent.variables.LabelFoundF}] = 6

return values
}

"LabelFoundA": "Off", "LabelFoundB": "Trip", "LabelFoundC": "-8", "LabelFoundD": "16", "LabelFoundE": "OffB", "LabelFoundF": "Dot" 

(the above used in a clone object)

Well yes it depends on the contents of variables

Now I just have the problem that some of the switches are showing in the wrong place!

Another subtility now with numbers as keys (-8 and 16), which you can avoid by forcing them to strings this way:

JS{
var values = {}

values[@{parent.variables.LabelFoundA}] = 1
values[@{parent.variables.LabelFoundB}] = 2
values[@{parent.variables.LabelFoundC} + " "] = 3
values[@{parent.variables.LabelFoundD} + " "] = 4
values[@{parent.variables.LabelFoundE}] = 5
values[@{parent.variables.LabelFoundF}] = 6

return values

Perfect, many thanks!

sorry guys but i can't get what you get

So i tried that :

So any help would be appreciated :slight_smile:

you need to define the listed variables in the parent. The panel that contains my switch looks like this:

Thanks but that's what i did no ?
The parent of my switch is root. So...

You wrote in the root's value property, should be variables.

yep i did this... :slight_smile:

Now let's say i want to store this variables into a variable script called conf
How to get the values ?

image

image

@{conf.foo} would return the property foo of the widget with id conf, You should write @{conf}.foo (retreives the value and then the property foo in that object).

1 Like

okay but can't figure out how to get the keys of the object.
i want to have "foo" and "other" as label for the switch and not the value stored.

image

image

i'm lost in syntax.

There may be a better built in way but Object.keys is probably what you're looking for. As in:

JS{ 
  var v= []; 

  v[0] = @{conf.comments}; 
  v[1]= Object.keys(@{conf})[0]; 
  v[2] = Object.keys(@{conf})[1]; 

  return v;
}

thanks @erictheise

So

image


image

image

Cheers