Tuesday, October 4, 2022
HomeE-LearningRandom numbers in Captivate - eLearning

Random numbers in Captivate – eLearning


Randomizing exists in some restricted conditions in Captivate:

  • Query swimming pools enable so as to add randomized quiz slides to a challenge.
  • Shuffle characteristic for a number of query varieties will be seen as randomizing.

In all different conditions you might want to add some JavaScript to get a randomized quantity (or textual content). This quick weblog is supposed as a solution to a person request within the eLearning group, to be discovered below this hyperlink. In my weblog you’ll discover a number of examples of randomizing for video games. It is a quite simple instance for the reason that person solely needs to have a random card chosen from a deck on clicking the deck. A second click on on the deck must flip again to the duvet of the playing cards.

There is just one slide on this challenge apart from the Title slide. The three (tarot) decks are equivalent, have 14 playing cards. Strive it out. You might get some concepts methods to use this workflow for video games. Sooner or later I’ll submit extra examples of this workflow in a much bigger tutorial challenge.

This instance will be watched under (fastened dimension) or you’ll be able to click on this hyperlink for a rescalable model.

Play

The timeline of the tarot slide exhibits the three decks. Every deck has a Click on field on high of the deck, which can set off a complicated motion with embedded JavaScript. I hear exclamations! Why not use the deck itself (PNG picture) as interactive object. It’s unimaginable as a result of JS is used to alter the state of the article, and it’s unimaginable in that case to make use of the picture itself as button. That is annoying, as a result of a responsive challenge with Fluid Packing containers is not going to enable stacking of the press field with the multistate object in the identical location. You would want a button in one other location. For a non-responsive challenge (like this instance) it’s not an issue.

Multistate object (deck)

Decks are multistate objects with 15 states. The Regular state exhibits the duvet. As a result of script the labeling is vital for the opposite customized states. They’re all labeled Cardx  – x is a quantity corresponding with the rank of the cardboard. The three decks within the instance are equivalent, however you’ll be able to have decks with a unique variety of playing cards, simply use the identical logic for the numbering. Have a look at the Object state panel for Deck1:

Variables 

In Captivate I would like just one variable for every deck to observe up the standing: is it exhibiting the duvet, or a random card? Two prospects signifies that I can use a Boolean variable. When the duvet is seen, the variable has the worth 0, for a random card it has the worth 1.

Superior Actions

Click on packing containers set off a conditional advanc motion. Right here is the motion for the primary click on field (CB_1) over Deck1:

The Boolean variable v_1 is checked. If it has the worth 0, a random card must be proven which is completed by a JS script (see under), and the variable is toggled to 1. If it has the worth 1, the duvet (which is the Regular state) is proven.

For the second and third deck, the variable and the identify of the deck have to be edited.

Javascript

The used trick is to create the identify of the state by concatenation of two strings:

  • First string is all the time ‘Deck1’.
  • Second string is a random quantity between 1 and 14, transformed to string.

I’ve defined in depth using “Math.flooring(Math.random()*(max-min))+min)” in an older weblog submit:

Taking part in-with-numbers-part-1

That random quantity is transformed to a string with a JS technique. Results of the concatenation is the identify of one of many states within the deck multistate object.

For the second and third deck, the deck identify have to be modified on this script. In case you do have roughly playing cards in these decks you might want to edit the utmost quantity (right here set at 15).

This primary instance might have ignited your artistic juices? What about creation of a jackpot recreation? A humorous arithmetic train to your youngsters? A board recreation the place you employ a cube?

For this use case it’s unimaginable to create a shared motion. Considered one of my long-standing characteristic requests for actions is the chance to generate a command utilizing concatenation. A second one: having the ability to change a state primarily based on a variable as a substitute of a literal identify of the state. You would help my requests

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments