Featured Categories
-
Lectora®
Lectora® is the most trusted authoring tool in the world. Rock out your creativity! Author courses any way you like. Lectora adheres to best practices for Accessibility and Web Content Accessibility Guidelines (WCAG), offers responsive authoring for eLearning, and publishes to any LMS (Learning Management System).
-
CenarioVR®
Experience virtual reality through CenarioVR®, our training and virtual reality (VR) authoring software that allows you to create immersive learning in minutes! No coding required!
-
Rockstar Learning Platform®
Our Rockstar Learning Platform® has all the features you’ll love. Help your employees be better at their jobs, more valuable to your company, and most effective in servicing your customers.
-
The Training Arcade®
Level up your learner engagement with the Training Arcade®! The Training Arcade is a library of fun, mobile-ready, casual games that can be rapidly customized with your content to create effective gaming!
-
ELB Learning Content
Did you know that our AssetLibrary™ has over 120 million engaging, interactive, and awe-inspiring templates and assets to help you become an eLearning Rockstar®?
Variables in games

I'm designing a game where users roll two dices and then pick the question to answer. Rolling the dices activates all questions' buttons. Is there a way to activate only the button that associates with the total numbers on the dice tiles? For example, if the total number of dice tiles shows 10, then question 10 only becomes active.
I know this needs a variable, but I was not able to reach to it thus far.
Thank you,
Comments
-
Thank you Tim. Here's what I did:
1- Saved images for each tile of each dice.
2- Grouped the 6 images and called them Dice 1; same with the other 6 images and called them Dice 2
3- Created 2 variables and called them Dice 1 and Dice 2
4- On the Roll button I added actions to Modify the Variable of Dice 1 to set to Random (0,6), and then Change Content of the dice image to the side image if the dice variable is equal to 1, 2, etc. For instance: Change Content, Target: Dice, Resource: Dice-side 1 If Dice_1 (the variable) is Equal to 1; and so on. (please see attachments).
So basically, I didn't use calculations to roll the dice. I just enabled and disabled the questions buttons with the click on the Rolling button, and used the Move to action to move the dice while rolling.
Now, I want to do some math and enable only the question when the sum of the two dices' sides is equal to the number of question. For example, the two dices' total is 6, then question 6 becomes active.
How do I do that?
Thank you -
So, you do know how variables work... the math part is simpler than what you've got so far. Just create a third variable, e.g. "Both_Dice", and two actions after those that randomly set the two dice:
On: Click
Action: Modify variable
Target: Both_Dice
Type: Set equal to
Value: VAR(Dice1)
On: Click
Action: Modify variable
Target: Both_Dice
Type: Add to variable
Value: VAR(Dice2)
... make sure it matches the correct names, yours won't have blanks have they?
"Both_Dice" now contains the sum of the two value.
Then add actions similar to those changing the images:
Action: Set state
Target: Button 1
State: Enable
If "Both_Dice" equal to "1"
You'll need 1 for each button / for each value "Both_Dice" might have. -
-
Tim or others,
One more question on the same topic: Dice Rolling. How do I limit the results of the rolled dice to the numbers of unanswered questions? Meaning: if question 9 is answered, I don't want the dices total to land on 9. There are 10 questions in this game, and if the users answer 5 questions, they still have to roll over and over until the total lands randomly on an unanswered question.
Any help please?
Thank you. -
That's tricky with the Actions system. It would be easy in code, but Actions have no way to handle a list of numbers.
You can use the question variables (see https://www.trivantis.com/blog/lectora-basics-question-variables/) and a series of Conditions on the goto action to reject going to an already-answered question, but I don't off the top of my head see an obvious way to trigger the action again. (It would be trivial to pop up a message saying, "Please roll again." It would also be clunky and frustrating for the user.)
What is missing is the ability to have an Action trigger itself again if it gets an invalid result.
EDIT: if you are comfortable with even very basic JavaScript (which is all I personally know) you could have the button trigger a script rather easily--that's a supported Action type. That script could set a variable, and could read the Question variables and make sure the result is limited to un-answered questions. -
-
-
Here's a sample how it can be done with Lectora alone. It does require quite a lot of actions...
-
-
The system uses 5 variables:
die1value, die2value, totalvalue: These are the same as before.
repeat: Either "yes" or "no". It's used during "Check Results" to decide whether new random values are required for die1value and die2value, because the totalvalue has been rolled before.
questions: It contains characters, a - k, to represent each possible "totalvalue", 2 - 12, i.e. a=2, b=3 etc
The group "Enable ..." is what happens when a valid number is rolled. Currently there are two actions for each "totalvalue".
If totalvalue = 2, Button 2 is enabled and "a" (representing "2") is subtracted from "questions".
When another 2 is rolled, "Check Results" will find that "totalvalue = 2" but "questions" Does not contain "a". "repeat" stays "yes" and the last action the group will run "Randomize Dice" again to receive new values.
You can use any action you want instead of "Enable Button", e.g. "Show Question 1" or "Go to page 15".
You can move the "Subtract a" action to another location, e.g. to the page with the question, to the check button and give it different conditions, e.g. "If Question 1 is correct". -
Thanks a lot Tim, this is a very helpful explanation. I wish I had had these variables even before I design the game. My challenge is that my game has already its own variables that do other functions besides the dice rolling. I'm trying to merge yours with mine, while maintaining those functions running. With the many actions, it's quite difficult to manage all of them.
I'll keep you posted...
Many thanks again,
-
@Tim,
This maybe too late, but I'm indebted to you with a big thank you. A year after you gave me this advice, I was able to apply it during my annual update of the training. Your zip file was so helpful and the trick is super convenient. It saved the time of random rolling of dice.
Thank you so much, -
@timk and @tmichael9734 you guys are both Lectora Rockstars! Thank you for being a part of our community!----------------------------------------------
Chris Willis, Product Director, Lectora
◖⚆ᴥ⚆◗ "Where there's a Willis, There's a Way!"
Categories
- 35.9K All Categories
- 110 ✫ Announcements
- 33.2K Lectora®
- 31.1K Lectora Discussions
- 29K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 27 ELB Learning Content
- 27 ELB Learning Content Discussions
- 346 CenarioVR®
- 205 CenarioVR Discussions
- 141 CenarioVR Feature Requests
- 44 Rockstar Learning Platform®
- 41 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 48 ReviewLink®
- 48 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 938 All Things eLearning
- 39 eLearning Development
- 546 Learning Management System (LMS) Integration
- 333 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products