Random Number generator

May 24, 2012

I'm not sure if anyone has done this before - I've seen a number of requests for a random number generator. So I've thrown this together - give it a whirl.... Story is attached.

Lance

49 Replies
Andrew Probert

So I feel like I followed everything here for using javascript to generate a random number and its not working for me.  I checked out another screenr tutorial for doing and the javascript was slightly different so I tried that as well and nothing.  Any help as to where I'm going wrong would be greatly appreciated.  

Thanks

Michael Hinze

Andrew Probert said:

So I feel like I followed everything here for using javascript to generate a random number and its not working for me.  I checked out another screenr tutorial for doing and the javascript was slightly different so I tried that as well and nothing.  Any help as to where I'm going wrong would be greatly appreciated.  

Thanks


There was a typo in the second line of your JavaScript, it should be: var player = GetPlayer();

Cal Osborne

I just thought I'd post this as a reference and open it up to feedback about the method and the merits of using this method. My requirement is to have 8 branching scenarios, of which the user will start at any random point and only do 4 of them.

I have set a variable that increments every .1 of a second and based on the current state of the variable it will then take you to that scene number. The first slide is on a 1 second loop so the variable is always changing. So, although not a true random, it is highly unlikely that a user will click the 'Start' button at exactly the same point each time.

Any comments or feedback is welcomed.

Adam Hain

Hey everyone,

I am using code similar to Sagar's dice game above. I can assign a random number to a variable when the user clicks a button and it works great using JavaScript.  However, I'd like to assign 5 unique random numbers to 5 variables  between 1 and 200.  There are a few different methods out there in JS forums but I wanted to your thoughts.  

Thanks!!

Elizabeth Blakemore

Hello,  I have only been using Storyline 2 for a short while (and never used JavaScript before) but want to use the JavaScript above to generate random numbers.  I have created a variable entitled "Randnum" and inserted a button to trigger the Execute JavaScript command - and the script being  var number=Math.floor(Math.random()*7);
GetPlayer().SetVar("RandNum",number);

When I publish and click my button the variable remains on 0 and doesn't generate a random number.  Please tell me what I am doing wrong.  Many thanks in anticipation.

James Bonney

Sorry to bring back an old thread to life again, but I'm having a problem with making Javascript change a number variable, 'randnum'.

I've added a screenshot below showing the variable reference, the script and also the trigger.

When I publish it to test locally, the number variable just shows 0 which is the default value.....any ideas on what I'm doing wrong?

I want it to work so when a users clicks on a Dice, the script will run and in course change the state of the Dice to the respective number 1-6.

Storyline screenshot

Christie Pollick

Hi, James -- I just wanted to stop in to note that as this thread is a bit older, you are welcome to reach out to any of the participants directly using the 'Contact Me' link on their profile page (in case they are no longer subscribed). 

Also, in case you weren't aware, we are not able to provide support for JavaScript, but here is the JS Best Practices sheet if you'd like to take a look. :)

Mark Shepherd

Hi guys:

Loving this thread. :)

Ok, so I tried to build a JavaScript randomizer using a dedicated JS Script trigger, and it worked very nicely once I tweaked the syntax a little.

HOWEVER:

Not all learners have and/or use JavaScript, so that kind of caused some issues in terms of things working as-expected.

Also, I would see cases where my JS code and triggers would not always work consistently, despite different users using the same browser (Internet Explorer), and even confirming that JavaScript was enabled in that browser, so that was frustrating.

As a result, I switched over to a "pure" all-Articulate Storyline 2 solution of using a random QB draw using fixed blank slides within the Question Bank that set a variable value, and this is working MUCH better, even opening up possibilities for potential reusability via parallel variable trackers/option paths.

Thanks to everyone for the samples.  Very helpful and instructive. :)

 

This discussion is closed. You can start a new discussion or contact Articulate Support.