March 4, 2020 at 2:10 PM #440064
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,March 4, 2020 at 4:50 PM #440068
How did you program the dice … without variables to decide which value each shows?March 5, 2020 at 8:22 AM #440148
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?
Attachments:March 5, 2020 at 12:20 PM #440174
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:
Action: Modify variable
Type: Set equal to
Action: Modify variable
Type: Add to variable
… 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
If “Both_Dice” equal to “1”
You’ll need 1 for each button / for each value “Both_Dice” might have.March 5, 2020 at 2:11 PM #440186
That was easy!!!
Thanks a lot Tim, that solved the problem and assigned the dices to the correct question numbers.
Thank you so very much,June 18, 2020 at 9:21 AM #446563
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.June 19, 2020 at 3:35 PM #446630
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.
June 22, 2020 at 5:44 AM #446689
- This reply was modified 4 months, 1 week ago by CarlFink .
Thank you Carl. I know it is rather very difficult with variables and actions than if it is built in Java Script. Unfortunately, I’m clueless in Java Scripts. All what I know is to copy and paste them but cannot create them.
Many thanks again for your attempt though:)June 22, 2020 at 8:48 AM #446710
It’s times like this I miss Asymetrix ActionScript.June 22, 2020 at 8:52 AM #446713
True! Thank you Carl:)June 22, 2020 at 11:43 AM #446730
Here’s a sample how it can be done with Lectora alone. It does require quite a lot of actions…
Attachments:June 22, 2020 at 12:26 PM #446737
This is nice Tim, thank you for sharing it. Let me challenge myself now and see if I can apply it. It’s exactly what I’m looking for! I wish I can do it.June 22, 2020 at 4:39 PM #446753
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”.
June 23, 2020 at 7:18 AM #446768
- This reply was modified 4 months, 1 week ago by Tim K.
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,
You must be logged in to reply to this topic.