| sample images | finished movie |

Lingo - Random

Created and designed by Vivienne Trulock for ilikecake, 2005

Dice

Many games include a random event occurring, such as the roll of a dice or a random card being selected, to determine subsequent events. This tutorial will help you to create a random dice. See finished movie.

Import 7 images, 6 showing a different face of a die. Place them on the score in rows 1 to 6. In row 7 place the 'roll the dice' button.

dice position on score

To make the illusion of a dice work, all the dice faces should be in the same position.

dice postion on stage

Lingo Script

We need to turn off the visibility of each of the faces of the die, so that when we turn one of them on, it is visible as the result of the dice roll. This goes in a sprite script attached to the 'roll the dice' button, and will be executed when the user presses the mouse DOWN.

on mouseDown me
sprite(6).visible=FALSE
sprite(5).visible=FALSE
sprite(4).visible=FALSE
sprite(3).visible=FALSE
sprite(2).visible=FALSE
sprite(1).visible=FALSE
end

The second part of the script instructs the computer to set the visibility of a random sprite to TRUE. This is executed in the mouse UP stroke.

on mouseUp me
sprite(random(6)).visible=TRUE
end

All of the previous script is placed the script attached to the 'roll the dice' button.

The only other script needed is placed in the last frame of the movie, and keeps the playback head looping.

on exitFrame me
go to the frame
end

Completed Movie

The final dice movie should look like this.

Valid CSS! Valid XHTML 1.0 Strict Level Triple-A Conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0 default text high contrast text large text large and high contrast text