Random Number/Dice Roll without Javascript?

Jun 19, 2017

Hi, all:

Just curious if there's a workaround for creating board games with dice rolls/random number and question generators without using Javascript. I've been looking at a few examples to get an idea of how it's done, and it looks like for the most part they all use Javascript. I'd love some pointers on where to start!

Thanks in advance! 

3 Replies
OWEN HOLT

Don't let JavaScript intimidate you, there are lots of people here ready to help. :-)

That being said....  and maybe not the most elegant solution, but you could do the following to get a number between 1 and 6 without using any JavaScript:

  1. Create a number variable and a T/F variable
  2. Insert an object off of the slide that you can animate.
    1. Add a motion path animation
    2. Set the animation to the shortest possible duration (I think it is .10)
    3. Add the following actions to the object
      1. Move Object on Line Motion Path 1 when the timeline starts (this action should already be there from adding the motion path. Delete this if you want the user to start generating the 1st number using a button or object)
      2. Add 1 to NumberVariable when the Line Motion Path 1 completes If NumberVariable is Less than 6
      3. Subtract 5 from NumberVariable when the Line Motion Path 1 completes If NumberVariable is equal to 6
      4. Move Object on Line Motion Path 1 when the Line Motion Path 1 completes If TrueFalseVariable is equal to True
  3. Add 2 buttons or other objects that will start and stop the animation
  4. Add the following trigger to the button or object that will stop the animation and give you a number
    1.  Set TrueFalseVariable equal to False when the user clicks
  5. Add the following trigger to the button or object that will start or restart the animation used to generate the random numbers
    1. Set TrueFalseVariable equal to True when the user clicks
    2. Move Object on Line Motion Path 1 when the user clicks

Basically this will count from 1 to 6 very quickly until the user stops it. The "randomness" would be determined by how long the user waits between starting and stopping the "die roll".

Katie Farron

This is fantastic, thank you! I was able to duplicate one on my own. Now the question becomes this...if I want the piece to move around the board based on the die roll, how do I set the triggers? I currently have the game piece state set to Normal, which is on the starting space, and I have different "states" for each space. (For example, "1" is the piece moved forward to the next spot, etc)

I'm running into some confusion getting it to move based on the die roll, because I can get it to go for the first 6, but counting from there gets a little buggy. Does my question make sense? If not, I can try to post my Story file. 

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