Greetings, i have searched for how to make a rolling dice, i couldn't find one. So i tried to make one and finally i was able to make one.
Getting Started
First, insert a sprite called "Dice".
Frame Zero
Frame One
Frame Two
Frame Three
Frame Four
Frame Five
Set it's animation speed to 0 and repeat count to 2.
Insert mouse and add another sprite for roll the dice.
Events
Add a global variable called "dice" and set it's value to 0.
Event: Mouse -> On object clicked -> rolldicesprite
Action: Dice -> set animation speed -> 10
System -> set global variable -> dice=0
Dice -> start animation from beginning
Event: Dice -> On animation "default" finished
Action: System -> set value -> Dice=random(7)
So it's value will be set less than 7.
Then add these events:
Your dice is ready!
You are ready to roll your dice. Also there is a capx file for who has problems with it. Good luck!
EDIT
A simpler version only requires 2 events and make a better use of the random action.
See the file "diceexample_simpler.capx"
Event 2 :
Event: Dice -> On animation "default" finished
Action: System -> set value -> Dice=int(random(6))
So it's value will be set less than 6 and will only return integers (so either 0, 1, 2, 3, 4 or 5).
Action: Dice -> Set animation frame to Dice
And here you have it, without the need for the tedious checks and only set once when the animation is finished.
You can also check out "diceexample_variousSpeeds" which proposes to have several roll speeds before having the result displayed, slowing down a bit in the end.