Modify storyline variable with a variable that derives from a javascript
Feb 18, 2024
Hello all dear guys, I take this opportunity to thank you and congratulate you all because you are very good and many have saved me with this forum!
This time I'm having trouble with a Javascript that doesn't pass the numbers variable to Articulate.
- Basically, with the "Execute Javascript" trigger I run this script when timeline starts on a slide:
var variableValues = [tempo_q1, tempo_q1_2, tempo_q1_3, tempo_q1_4];
var ValoreMax = Math.max.apply(null, variableValues);
player.SetVar("Valore_Max", ValoreMax);
(It should compare 4 variables and choose the variable with the highest value from them and pass it to an Articulate variable) - In the next slide I insert a text box with the variable %Valore_Max% that should make me see the value generated by the javascript
So why can't I see the variable correctly when I export the project?
Thank you very much, any support you will give me I am sure will be a great help!
4 Replies
Maria. Can you include the full JavaScript for the trigger, or upload the .story file (or an example version that demonstrates the problem)?
Have you assigned player via GetPlayer() and assigned the tempo_q1 variables via GetVar()?
Hello, sure!
The game involves clicking on the red dot that appears on each screen, each slide tracks the time spent in the "tempo_q1" variable.
The javascript on the slide "CONTEGGIO" should find what the highest value is and present it in the "Result slide" with the variable %Valore_Max%
Thanks again!
I think you just need to declare the player variable and read in the tempo variables from Storyline first.
Change the contents of your fist (currently disabled) executeJavaScript trigger on CONTEGGIO to the following, and enable the trigger.
let player = GetPlayer();
let tempo_q1 = player.GetVar("tempo_q1");
let tempo_q1_2 = player.GetVar("tempo_q1_2");
let tempo_q1_3 = player.GetVar("tempo_q1_3");
let tempo_q1_4 = player.GetVar("tempo_q1_4");
let tempo_q1_5 = player.GetVar("tempo_q1_5");
let tempo_q1_6 = player.GetVar("tempo_q1_6");
let tempo_q1_7 = player.GetVar("tempo_q1_7");
let tempo_q1_8 = player.GetVar("tempo_q1_8");
let tempo_q1_9 = player.GetVar("tempo_q1_9");
let tempo_q1_10 = player.GetVar("tempo_q1_10");
let tempo_q1_11 = player.GetVar("tempo_q1_11");
let tempo_q1_12 = player.GetVar("tempo_q1_12");
let tempo_q1_13 = player.GetVar("tempo_q1_13");
let tempo_q1_14 = player.GetVar("tempo_q1_14");
let tempo_q1_15 = player.GetVar("tempo_q1_15");
let tempo_q1_16 = player.GetVar("tempo_q1_16");
let tempo_q1_17 = player.GetVar("tempo_q1_17");
let tempo_q1_18 = player.GetVar("tempo_q1_18");
let tempo_q1_19 = player.GetVar("tempo_q1_19");
let tempo_q1_20 = player.GetVar("tempo_q1_20");
let tempo_q1_21 = player.GetVar("tempo_q1_21");
let tempo_q1_22 = player.GetVar("tempo_q1_22");
let tempo_q1_23 = player.GetVar("tempo_q1_23");
let tempo_q1_24 = player.GetVar("tempo_q1_24");
let tempo_q1_25 = player.GetVar("tempo_q1_25");
var variableValues = [tempo_q1, tempo_q1_2, tempo_q1_3, tempo_q1_4, tempo_q1_5, tempo_q1_6, tempo_q1_7, tempo_q1_8, tempo_q1_9, tempo_q1_10, tempo_q1_11, tempo_q1_12, tempo_q1_13, tempo_q1_14, tempo_q1_15, tempo_q1_16, tempo_q1_17, tempo_q1_18, tempo_q1_19, tempo_q1_20, tempo_q1_21, tempo_q1_22, tempo_q1_23, tempo_q1_24, tempo_q1_25];
var ValoreMax = Math.max.apply(null, variableValues);
player.SetVar("Valore_Max", ValoreMax);
Nathanial, thank you so much! It works great!
So the mistake was that I didn't take the variables from storyline to use in javascript.
Thank you very much, I hope this post will help many people!