Randomly Playing Tracks
For this script, the project has four tracks, and you want a script to randomly choose one
to play once a menu times out (has been inactive for a set amount of time).
For this script, you’ll call the tracks “Ocean,” “Beach,” “Trail,” and “Shopping.”
To create a Random Play script
1
Do one of the following:
• Choose Project > Add to Project > Script, or press Command–Single Quote (’).
• Click Add Script in the toolbar.
2
Double-click the new script in the Outline or Graphical tab.
518
Chapter 20
Creating Scripts
The Script Editor opens and the Script Inspector appears.
3
In the Inspector, name the script
Random Play
.
4
In the Script Editor, select the first command line (Nop).
The Script Command Inspector appears.
5
In the Script Command Inspector, choose Set GPRM as the command.
6
To configure the set GPRM command:
a
Choose “ran” as the Operation.
b
Choose Immediate as the Source Type.
c
Enter 4 as the Source Value.
d
Choose GPRM 0 as the Target.
The above settings generate a random number between 1 and 4 and place the value in
GPRM 0. It is this value that is looked at by the next commands in this script to determine
which track to play.
7
In the Script Editor, click the Add button.
The next command line is added to the script.
8
In the Script Command Inspector, choose Jump as the command.
9
To configure the jump command, choose Tracks and Stories > Ocean > Marker 1 from
the Jump To pop-up menu. This plays the first of the four tracks, depending on the result
of the compare function added next.
Note: Remember that the Ocean track is fictitious. Unless you created a track called Ocean,
you won’t see it in this pop-up menu.
10
Add a compare function to the jump command to test to see if this track has been selected
with the random generator.
a
Select the Compare Command checkbox.
b
Choose GPRM 0 as the “Execute if” element to be compared to.
c
Choose equal (=) as the “is” compare operation type.
d
Choose Immediate as the “to” element type to compare.
e
Enter 1 as the “with value.”
If GPRM 0 has a 1 in it (generated by the random number generator command), this jump
command occurs. If not, the script moves to the next command.
519
Chapter 20
Creating Scripts
11
Add three additional jump command lines—one for each of the other three fictitious
tracks. The only differences are the Jump To settings which need to match each track
(Tracks and Stories > Beach > Marker 1; Tracks and Stories > Trail > Marker 1; and Tracks
and Stories > Shopping > Marker 1) and the immediate values in the compare function’s
“with value” field (use 2 for the Beach track, 3 for the Trail track, and 4 for the Shopping
track).
12
You need to configure the menu’s timeout setting by selecting the menu in the Outline
or Graphical tab, then clicking the General tab in the Menu Inspector. Choose Timeout
from the At End pop-up menu and enter a value (in seconds) for the timeout. Choose
this script (Random Play) from the Action pop-up menu.
Each time the menu sits idle for the specified amount of time, the script starts, generates
a random number, and then plays one of the four tracks. Once the track ends, it jumps
to the element specified by its End Jump setting.