Scripting question about a dynamic variable

Hi there! After trying fruitlessly for an hour trying to get this to work, thought I would try here, hope someone can help. I have a really simple bit of code that I just cannot for the life of me get to work!

var Col1 = "#ff0025" //Red
var Col2 = '#0099ff' //Blue
var CardCol = 1
var ColNum = "Col" + CardCol.toString()
setVar('KK' + MasterSlot + 'Macro'+parameter1, 'Col', 'Col'.CardCol)

I cannot get 'Col'.CardCol (or ColNum even!) to return the actual variable Col1 (ie "#ff0025") to set the widget's colour dynamically, it just returns 'Col1' in the console!

Apologies this is a basic query (have been googling Javascript forums but cannot find a suitable solution!) :grin: Any help greatly appreciated as always!

Ha, have managed to solve this with a bit more research! :grin: This seems to do the trick (don't know if it is the best method mind)!

var obj = {
"1": "#ff0025",
"2": '#0099ff',

var key = CardCol;
setVar('KK' + MasterSlot + 'Macro'+parameter1, 'Col', obj[key])

Back to coding thanks!

1 Like