Rolling Dice demo and Random Question Draw workaround

Jun 18, 2013

Successfully solved a couple of problems today so I'm sharing my methodology in case it helps someone else.

I was creating a game and I wanted to simulate the rolling of dice (well, I went with a single die in the end).  I wanted the die to roll randomly and add to a score.  (The score changed the position of the game piece on the board, which I controlled with states).

Stealing the javascript from the thread here - http://community.articulate.com/forums/p/13240/118945.aspx#118945 - kindly posted by Colin Harm, I was able to get the effect I wanted.  I've shared  the basics of it here to save someone else the trouble of figuring out how to do it.  (Note that you will need to 'publish' the story file to see it work because Javascript doesn't work in preview).

You can see that each roll of the die takes you to a layer which change the appearance of the die. 

Now on to my second problem solve.  From my layers I actually sent my learner to a question draw.  My question bank had 50 questions in it but my problem was from the layer I could only send them to the same draw over and over.  (This is a known problem with question draws, they are only random the first time).  You can reset the question but they will keep getting the same question.  So I realised I could use the same javascript from the die to create a random generator to send my users to different question draws from the same question bank each time they came to the same layer.

First I added a button to each layer inviting the user to attempt the question.  I created a variable called 'RandDraw'.  The first trigger on the button was to execute Javascript.  The Javascript was:

var number=Math.floor(Math.random()*49);
GetPlayer().SetVar("RandDraw",number);

I then created lines of code that said:

'Jump to Question Draw 1.2 if RandDraw is equal to 2'

'Jump to Question Draw 1.3 if RandDraw is equal to 3'

etc etc.  You could put as many draws as you want just as long as every random number is associated with a draw.  This needs to be repeated on every layer.  (get it right on one layer then copy the layers is the easiest thing).

This results in the same button sending the user to a different draw from the same question bank randomly.  There is a possibility they will end up with the same question more than once but the more draws you put in, the less likely that is.  In my particular application I didn't mind if they occasionally got a repeat question.

Note also that the javascript generates numbers from 0 to 1 less than the number you created.  e.g. for the die, it generated 6 numbers - 0, 1, 2, 3, 4 and 5.  I just linked 0 to 1, 1 to 2 etc.)

Well, hope this helps someone. 

16 Replies
Matthew Kliewer

Cool! I've been thinking about a way to incorporate rolling dice into a learning game, but I hadn't thought about this one.

I made a Farkle dice game last year (just the game, no learning component) and setting up game logic like this can be complicated, but rewarding when it works.

One JavaScript tip is to add +1 to your random formula so your dice values are 1 to 1 (just makes it easier later, for me):

(P.S. - I was unable to get the published files to work in Google Chrome for some reason, but it worked fine in IE10. Could just be my computer, but just letting you know in case you were going to use this in a real scenario.)

Miriam de Jonge

Thanks Matthew - when I was looking for a dice solution I saw your Farkle game and admired it!  Thanks for the tip about the +1, makes sense.

Hmmm about the Google Chrome, no idea how to resolve that.  I've just been kind of assuming that things I building in Articulate are going to work on different browsers, but I'm not at that stage of testing yet.  I guess Javascript is the thing creating trouble? 

Miriam de Jonge

Ah poo.

For anyone who was following this thread on further testing it seems my randomizing of the question draw doesn't quite work.  When you visit a question draw you have visited before, sometimes (for reasons I don't understand) the question doesn't work.  Even though it is set to return to initial state when you return.

If I figure out another solution to this problem I'll add it here!

Gayla Keesee

Miriam, still following this thread. Hope you can figure out a solution.

Regarding the javascript and Google Chrome issue--I learned that javascript really only works well with IE and Safari. So, a disadvantage of incorporating the code in your Storyline file. Might need to include a note at the beginning indicating that if the user has difficulty, switch to IE or Safari to run. Also learned in another thread that javascript doesn't work for mobiles.

Gayla Keesee

I have been looking for a game board template that I could easily adapt for the math course I am currently creating. Miriam's Snakes and Ladders is the closest I've come. So, I decided to play around with it to adapt it to the theme for my course, which has the going on a journey across the island, having to solve various math problems along the way that are put up as barriers by the Powers That Be that are in charge of the island.

I finally figured out how the states work to advance the game piece last night and realized that when I had repositioned the game board on the slide, I had messed up the states positions. I moved the board back and the position states worked when I hovered over them; however, when I publish the file, the game piece moves to a position below the game board and tracks around. I'm not sure what the problem is. NOTE: Since I am running javascript for the random number generator, I had to open the file in Internet Explorer. Forget Chrome and Firefox.

Also, I was wondering if there were any way to dismantle the requirement that learners must complete the game in less than 25 questions--without a lot of reprogramming?

Here's a link to my revised version: https://dl.dropboxusercontent.com/u/4506559/Journey.story
I thought I'd post my query to the Community Forums also.

I've also attached a copy of my original game board. I had thought to use a spinner, but couldn't figure out how to randomize the spins. I could set the different pointer positions on different slides like we did for the die position, but not sure of the javascript needed or how to set up the variables/conditions.

I had also wanted to include "challenge" and "chance" options that would have the learners run into challenges such as tornadoes, geysers, hails storms and have to compute a word problem based on the challenge. The chance option would allow them to move forward X number of spaces. I'd have to figure out how to program the variable for moving forward if...then.

I appreciate the amount of time it took to get all the programming done. Thanks for sharing.


BTW: I found the rolling dice and the sound on another game board thread: Game Counter Flickers--Rebecca Evans.

Rutwin Geuverink

Miriam Krajewski said:

Ah poo.

For anyone who was following this thread on further testing it seems my randomizing of the question draw doesn't quite work.  When you visit a question draw you have visited before, sometimes (for reasons I don't understand) the question doesn't work.  Even though it is set to return to initial state when you return.

If I figure out another solution to this problem I'll add it here!


Miriam,

Maybe I'm completely wrong here but could you try the following?

I had been breaking my head over this in a similar case where questions only randomized the first time round, I eventually solved it by adding an extra slide. I hope this will fix it for you as well.

  • Insert a new (blank) slide
  • Insert a Result Slide (new slide-->Quizzing-->Result Slides)
  • Create a trigger on the feedback layers of your questions (correct&incorrect), that sends learners to the new (blank) slide
  • Create 2 triggers on your new (blank) slide - when the timeline starts. The 1st trigger should Reset the results slide. The 2nd trigger should jump back to the question draw.

Kind regards,

Rutwin

 

Jacob Selin

Just started on a project creating a game where i need a dice. 
Does anyone know anything about the script randomizing the dice?
I want something that works no mather wich plattform the user are sitting on.

Perhaps Articulate are about to implement a way to randomize numbers and so on (a randomize generator)

*Blink with puppies eyes*  

Attila Arvai

Hi All,

I'm pretty new Storyline user, and I'm trying to get as much info from the web as I can, but now I'm a bit stuck...

This thread (and many more) gave me a lot of help and inspiration but I cannot find more anywhere. So the issue is:

I've created the "randnum" script, which works fine - for every button push it gives random number between 1&6.

In connection with this, 6 different layers were made, (simulating the roll of the dice).

What doesn't work:

I cannot make my playing piece move. I know I do something wrong, but I don't know what.

What I'd like to is almost the same as in the example: step forward as it's on the dice, but without question (later it might change). My plan is to create a monopoly-like board game, without classic end.

But if it's nearly impossible, a game like this also totally fine:)

Can you help me what are the essentials of moving object related to random numbers?

Thanks in advance

Attila

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