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
Do one of the following:
• Choose Project > Add to Project > Script, or press Command–Single Quote (’).
• Click Add Script in the toolbar.
Double-click the new script in the Outline or Graphical tab.
The Script Editor opens and the Script Inspector appears.
In the Inspector, name the script
In the Script Editor, select the first command line (Nop).
The Script Command Inspector appears.
In the Script Command Inspector, choose Set GPRM as the command.
To configure the set GPRM command:
Choose “ran” as the Operation.
Choose Immediate as the Source Type.
Enter 4 as the Source Value.
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.
In the Script Editor, click the Add button.
The next command line is added to the script.
In the Script Command Inspector, choose Jump as the command.
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.
Add a compare function to the jump command to test to see if this track has been selected
with the random generator.
Select the Compare Command checkbox.
Choose GPRM 0 as the “Execute if” element to be compared to.
Choose equal (=) as the “is” compare operation type.
Choose Immediate as the “to” element type to compare.
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.
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
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.