# Spin the Wheel

Sep 04, 2019

Hello,

I am creating a quiz game using Articulate Storyline. I am facing  a small challenge.

I have created 5 questions with a wheel design using triggers. The wheel spins and stops on a random number, then it jumps to the allocated question.
On the second spin, the same number might be repeated (Although, I added a trigger for each question) . For example: If the wheel stops on 2, the leaner answers Q2. This question must be marked as done and the wheel must NOT stop on 2 anymore. Is this a Javascript condition? Can anyone help me with it? I have attached the triggers used.

###### 9 Replies

Elisa, just wondering, will your students/users be taking the quiz more than once? If not, then it may be easier to skip the random number piece of this and just "fake" randomize it by having the spinning wheel stop at the same stops every time....

If they *will* be taking the quiz more than once then it may be worth the effort to make this work.

I'll have to noodle on it over night, but off the top of my head I think you will need 5 T/F variables, default of False, that you'll set to true when a number is spun. So if your wheel variable equals 4 then set Q4 variable to True.

The next trick will be to assign a value of 1-5 to the wheel variable based on the values of these T/F variables.

......... to be continued, unless someone figures this out.....

Hi Brian,

Thank you for your reply, No they will not repeat the quiz, but they will move on and answer another 5 questions and keep and at the end they will answer 10 questions.

I did create 5 T/F variables, default False ...

Elisa Nazarian

No they will not repeat the quiz

Elisa, while the random number generator would be very cool to figure out and use, I think it's overkill in this instance if learners/users will not be repeating the quiz.

If they're going to complete this interaction once and never see it again, I'd go with a far more simple approach:

1. Create a slide with your spinner, have the learner spin the wheel and on this first slide the spin will *always* be (for example) "4". The user is then taken to question number 4.
2. Next slide repeat the spin the wheel but on this slide the spin will always land on (again, for example) "1". The user is then taken to question number 1.
3. Repeat this 3 more times for questions 2, 3 and 5.

You give the appearance of random spinning but are controlling the outcome, which is much more simple to design than a random number spin.

If your learners will go through this interaction once and never see it again they will have no idea that the spinner isn't landing on a random number.

Hope this helps,

B

Hi Brian,

This is what I did. However, I thought I can solve it using a trigger bc while transition you see a small glitch. But it is working correctly.

Thank you.

Elisa

Good to hear! Glad you got it working Elisa

FYI
Should you need to generate a non-repeating random number from a range...

WHAT YOU NEED:

A variable to store a single text array formatted like this: 1,2,3,4,5,6,7,8,9,10,11.... through your top number. Separate values with a comma only; NOT a comma + space. In my example, the variable is named Text_Array and goes from 1 to 100.
A variable to receive your Random Number. This can be either a text or numeric variable depending on what you want to do with it. In my example, it is a text variable named Random.  My example doesn't do anything other than display the random number chosen, but obviously you would want to evaluate the value and then do something based on it like go to layer, play media, jump to slide, etc.
A variable to track how many items are left in your list. You will use this to track when you have used all of the numbers to do something different.
Something to trigger your JavaScript. I'm using a button.  Here is the JavaScript code commented out so you can see what it is doing:

//get the StoryLine player
var player=GetPlayer();

//get Storyline variable value as a string
var textArray=player.GetVar("Text_Array");

//Convert string to a numeric array
numArray=textArray.split(",").map(Number);

//Get a random number from the array and send it to StoryLine
var randNum = numArray[Math.floor(Math.random() * numArray.length)];
player.SetVar("Random",randNum);

//Remove the random number from your array and get the array's length
numArray.splice(numArray.indexOf(randNum), 1);
var itemsLeft=numArray.length;

//Convert array to a string and send it back to SL along with the array's length
textArray=numArray.map(String).toString();
player.SetVar("Items_Left", itemsLeft);
player.SetVar("Text_Array", textArray);

See it in action here.

OWEN HOLT

Should you need to generate a non-repeating random number from a range...

Owen, thank you for sharing this... Definitely going into my bookmarks