Can you reference a variable dynamically?

Hi again! Sorry to bother to all once more, but I am having a bit of trouble with syntax again! :slightly_smiling_face: I am trying to create a bit of (semi!) efficient code to capture preset names and store these in a panel's variables (number 1 to x). To save from having to repeat the same script over I wanted to do something like this:

setVar('PresetNameText', 'Lbl', '@{ChControlPanel.variables.1}')

but instead of referencing a variable named '1' like this '@{ChControlPanel.variables.1}', I would like instead to have a variable named 'FXSlot' (declared earlier in the script) to make this line of code dynamic, ie '@{ChControlPanel.variables.FXslot}'.

If I try the above method the whole variable comes back 'undefined' (even if I have declared 'FXslot' to be '1'). Is this possible with different syntax, or (more likely!) is there a better way to dynamically reference the panel variables?

Once again, any help really appreciated!

@{} should be avoided as much as possible in scripting properties, you should use get() or getProp() instead, and if I understand correctly it happens to provide a clean solution for you:

var FXslot = "foo"
var slotValue = getProp('ChControlPanel', 'variables')[FXslot]

setVar('PresetNameText', 'Lbl', slotValue)
1 Like

This is great, exactly what I was trying to do, can think of multiple uses for this code in my template too, so thank you once more for the solution (these examples are a god send for us non coders! :grin:)