Forum Discussion
Jürgen_Schoene_
3 months agoCommunity Member
your problem are the six variables - not created in Storyline
player.SetVar ("Top3_1_Label",Top1LabelForStoryline);
player.SetVar ("Top3_2_Label",Top2LabelForStoryline);
player.SetVar ("Top3_3_Label",Top3LabelForStoryline);
player.SetVar ("Top3_1_Value",Top1ValueForStoryline);
player.SetVar ("Top3_2_Value",Top2ValueForStoryline);
player.SetVar ("Top3_3_Value",Top3ValueForStoryline);
1st, 2nd, 3rd and 1st_Counter, 2nd_Counter, 3rd_Counter should be correct
here is a modernized JavaScript version of your script
let player = GetPlayer();
// used Storyline variables
// 'A_Counter' ... 'R_Counter'
// 'A_name' ... 'R_name'
let myArray = []
for( let i='A'.charCodeAt(0); i<='R'.charCodeAt(0); i++) {
let char = String.fromCharCode(i)
myArray.push({
counter: player.GetVar(char + "_Counter"),
name: player.GetVar(char + "_name")
})
}
console.log( "myArray unsorted: ", [...myArray] )
myArray.sort( (a, b) => b.counter - a.counter); // sort descending
console.log( "myArray sorted: ", [...myArray] )
player.SetVar("1st", myArray[0].name);
player.SetVar("2nd", myArray[1].name);
player.SetVar("3rd", myArray[2].name);
player.SetVar("1st_Counter", myArray[0].counter);
player.SetVar("2nd_Counter", myArray[1].counter);
player.SetVar("3rd_Counter", myArray[2].counter);
in the browser console (-> F12) you can see the debug info