Forum Discussion
Javascript: get variable's value (number)
You are mixing Arrays and Objects. Although that is fine, it makes things more complicated to get selected. But solvable ofcourse...
Like this....
var player = GetPlayer();var myarray = [{ key: 'Choice1', val: 5,},{ key: 'Choice2', val: 4,},{ key: 'Choice3', val: 6,},{ key: 'Choice4', val: 2,}];
var selectedChoice = myarray.find(function (choice) {return choice.key === 'Choice3';});console.log(selectedChoice);player.SetVar("output","key: "+selectedChoice.key+" val: "+selectedChoice.val);
Using the array.find functionality to find the proper Object... and because its an Object then using dot-syntax to select the values inside that Object.
Ah, you were having trouble with getting the variable from the player...well my answer not relevant then...although you might find use for it.
Related Content
- 10 months ago
- 10 months ago