Forum Discussion
Sort numbered variables
// Get the values of the 8 variables and put them in an array
var variables = [ player.GetVar("Variable1"),
player.GetVar("Variable2"),
player.GetVar("Variable3"),
player.GetVar("Variable4"),
player.GetVar("Variable5"),
player.GetVar("Variable6"),
player.GetVar("Variable7"),
player.GetVar("Variable8") ];
// Sort the array in descending order and get the top three values
var topThree = variables.sort((a, b) => b - a).slice(0, 3);
// Set the top three values back to Articulate variables if needed
player.SetVar("Top1", topThree[0]);
player.SetVar("Top2", topThree[1]);
player.SetVar("Top3", topThree[2]);
JS Script could be your helping hand.
Is the "Top1", "Top2", "Top3" the variables to report back into articulate to use to show the answers?
- JesseWu4 months agoCommunity Member
Yes. You create those variables in Articulate to host the result before you run the script. This script will assign them values when it is done running.
- MichellePike-564 months agoCommunity Member
Thank you for this. I am really not familiar with JS so not sure how it works. I have done all you have suggested, but its not populating the Top1, Top2 and Top3 variables. I am getting values NaN in Top2 and Top3. Really appreciate your help but I dont think I have the knowledge to try and use JS.
- JesseWu4 months agoCommunity Member
NAN stands for not a number. You can always share a storline file here so others can try to debug. Or just ask any gen AI you use do it for you.