"How to Lingo," Part 4: Using the Case Statement
Set up a new scene of 10 frames in your "How to Lingo" movie. Mark the beginning of this scene with a marker called "Case." Terminate the scene with a go to the frame behavior. Include a navigation button leading to this scene from your main menu, and stretch the sprites for your Main Menu and Quit buttons to cover this scene.
Create a text field named "randomText" and drag it into the new scene. This field will contain only single words (the English names of numbers), so give it a fairly large type size, a bold font, and centering.
Create two buttons. The first is called "randomNumber"; the second is called "randomColor." Drag these into your scene and position them under the text field. Give them appropriate labels.
Script the Cast Member Script for the first button to select at random a number from 1 to 10 and put the name of that number (for instance, "one," "three," "seven," et cetera) into the text field "randomText." You'll need to know two things here. First, how to assign text to a field. Try this:
Member("randomText").text = "sassafrass"
Next you'll need to know how to select a random value and pair it with output. This is where the mighty Case statement comes in. Consider:
Case random(3) of
1: Member("randomText").text = "lions"
2: Member("randomText").text = "tigers"
3: Member("randomText").text = "bears"
end case
Once you've got random number names coming into your text field at the press of the first button, write a Cast Member Script on the second button to randomly assign one of ten possible color values to the text field.
To do this, you need to know how colors are specified in Lingo. As in HTML, it's done with hexadecimal triplets--three numbers, each between 0 and 255, representing values for Red, Green, and Blue respectively. So the statement rgb(255,0,0) specifies bright red. By changing the RGB values you can mix an entire palette--though all you need here are ten options.
You'll also need to know how to apply a color to a Cast Member. Like so:
Member("randomText").color = rgb(255,0,0)
Finally, figure out how to adapt the Case statement to assign one of your ten colors to the "randomText" Cast Member.
|