Learn More Contact Now

Finally, a practical example! And we won't even need all the SPRMs or most of the GPRMs from last time as we create a video that plays its tracks in random order.

In fact, we'll only use a single GPRM - those are the variables that are ours-all-ours, remember? - plus a jump or two, a little math, and the conveniently-named Set GPRM Random command. Let's say you have four tracks of video, and you want them to cycle randomly ad infinitum - maybe you're at an exhibition or something, who knows.


We'll be using only three kinds of command. First, we'll set our variable, GPRM 0, to hold a special value called "ran" -- a big ol' random number. Next, we'll use some math to change that big ol' random number to a random number within the number of tracks we have. Finally, we'll tell the DVD player which track to skip to, depending on what the random number is.


  1. Create a script (Command-' is the keyboard shortcut, or you can find it in the Project->Add to Project menu). Rename it from Script 1 to "Randomly Pick Next Track" - this is probably easiest to do by clicking on the script in the Outline View (Cmd+5), then editing the name in the Script Inspector (bottom right of your screen).

  2. Open the new script in the Script editor by double-clicking. Now, click the "+" button twice times to add two new commands.


  3. Click on the first Nop, and, in the Script Inspector window to the right, change the command to Set GPRM. Under Operation, select ran. This simply takes our GPRM 0 - one of our variables - and sets it to a Big Ol' Random Number. DvdspSC3-2.png

  4. We want to bring the Big Ol' Random Number down to size - specifically, we want it to pick randomly between four things, not fifty-eleven things like it's doing when it's so big. To do this, we'll use a little bit of fancy math - the modulo function. "Modulo" is just a fancy name for "remainder." If we take a Big Ol' Number and divide it by, say, the number of tracks we have (4), the remainder can only be one of four things: 0, 1, 2, or 3.

    So let's do that. Click on the second Nop, and change the command to Set GPRM again. Now, in the Operation menu, pick mod for modulo. Under the Source menu, pick "Immediate" - that lets us type an arbitrary number to use for this operation. In this case, we have 4 tracks, so type 4 in the Source Value box. Leave the Target box saying GPRM0 - after all, this is the variable we want to do the modulo to.


  5. So now, GPRM0 contains either 0, 1, 2, or 3. Let's meet the important part of variables: using them to make decisions.

    Add a new command, and change it to "Jump." Set this first Jump to point to Track 1. Now, we'll throw in our variable: check the Compare Command box. We only want to go to Track 1 if our variable is containing the first possible value - so we want the Compare Command to read "Execute if GPRM0 is = to (Immediate) with value 0."


    Do the same thing for each of the other tracks - for Track 2, for example, "Execute if GPRM0 is = to (Immediate) with value 1." Track 3 = value 2, Track 4 = value 3, etc.

  6. The script is done, but now we need to actually use it. Simply assign the end jumps on all four of your tracks to "Randomly Pick Next Track." Or, if you want to save even more time, you could assign the "Randomly Pick Next Track" as the Pre-Script for your main menu. This way, when any track tries to return to the menu, the menu will send it to a new, random track. Nice. DvdspSC3-5.png

There is a faster way to do this, but it's pretty advanced for this stage in our series. If you're really up for a challenge, try to translate my verbal description below into a script:

The Indirect Jump function allows you to jump directly to the location on the DVD corresponding to the value that's stored in a variable. So you COULD eliminate ALL of those conditional jump commands, and replace them with one single Indirect Jump command. But there's a catch: the way DVDs match up locations to numbers is whacked. Just take my word for it - the beginning of Track 1 is location 49280 (why wouldn't it be?). Then, to get the number for each additional track, you add another 128 to that number. So, if you're wanting to try coding this, the commands you'll need will:

  1. Multiply GPRM0 by 128
  2. Add 49280 to GPRM0
  3. Indirect Jump to the value that GPRM0 is now holding

Listed below are 0 links to blogs that reference this entry: Scripting in DVD Studio, Part 3 - Random Play.

TrackBack URL for this entry: http://www.geniusdv.com/weblog/mt-tb.cgi/869

Receive FREE Tutorials by email:


    Avid Media Composer Training
  • Enrollment Cost: $50.00
  • 84 Media Composer Lectures
  • Includes Practice Media
  • Interactive Quizzes
  • Official Certificate of Completion
  • 30 Day Money Back Guarantee
  • Click to Enroll for 10% off!
    Final cut Pro X Training
  • Enrollment Cost: $20.00
  • 60 Final Cut Pro X Lectures
  • Includes Practice Media
  • Interactive Quizzes
  • Official Certificate of Completion
  • 30 Day Money Back Guarantee
  • Click to Enroll


Scripting in DVD Studio, Part 2: Understanding Variables was the previous entry in this blog.

Scripting in DVD Studio, Part 4: Parental Control (Reading System Variables) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.