Dice amd javascript
Oct 07, 2014
By
Jacob Selin
I hope that someone in this community can explain why my JavaScript aint working.
I got the following script.
var dice = Math.floor(Math.random()*6+1);
var player = GetPlayer();
player.SetVar ("monkey",dice);
Its executed on timeline start.
On the slide i got a textbox where i request "monkey" via %monkey%
But it does not work. The only thing i get is %monkey" writen on my slide.
What am i doing wrong?
6 Replies
if you have monkey on the slide, looks like the reference is wrong, as it should display blank until it has a value
Jacob,
To add to what Phil said, be sure of the following:
1. You have created a variable called monkey using Storyline's "Create a New Variable" feature.
2. Be sure the monkey variable is numeric and not a text variable.
3. Be sure there is no space between the percent signs and the variable name when typed on the slide: %monkey%
Hope that helps...
Done all of the above. Now the variable shows a zero (0).
Guess its because of the initial value of the variable wish means the javascript never are executed.
Has test the file in IE 11 and Google Chrome. Working in SL1
Just a typo in this line: player.SetVar ("monkey",dice);
There should be no space after SetVar:
player.SetVar("monkey",dice);
Works fine once that space is removed.
Ahh, thanks.
Sometimes you need a extra pair of eyes.
Works fine in IE, but not in Chrome.
well well, i've already requested Articulate to build a proper "randomizer".
Jacob, I think you'll find it works OK in Chrome if you post the published output to a web server and run it from there.
This discussion is closed. You can start a new discussion or contact Articulate Support.