Appendix B. Scripting 101 in DVD Studio Pro

BRUCE NAZARIAN

Have you been missing out on some DVD authoring fun? Scripting is the key to unlocking some of the advanced functionality of DVD Studio Pro. Some folks hesitate to try scripting because they don’t believe they understand it, but it’s actually quite simple.

What Is Scripting?

In DVD Studio Pro, scripts are the command elements that control DVD player navigation and presentation. Every DVD player has this command language built in, ready to perform cool functions, if you tell it to do so. Scripting is how you tell it.

Scripting commands work their magic by accessing some of the 24 defined System Parameters (SPRMs) and 8 of the 16 defined General Parameters (GPRMs) in the DVD player. There are 21 currently active SPRMs, but there are just a few that are used regularly.

DVD Studio Pro’s scripting language is not JavaScript, HTML, XML, or anything you may already be familiar with. It is its own unique language, and it’s reasonably easy to use. Yet, it can create some powerful actions in response to a menu button selection.

The important thing is this: DVD Studio Pro scripting is designed to make it easy for you to create sophisticated DVD behavior, without having to learn a complex DVD command language!

Why Use a Script?

One of the first things to learn about scripting is discovering what you can do with the script.

Scripts allow you to navigate various sections of the disc:

  • Navigate to a Menu (Jump To “MenuName”)

  • Navigate to a Button (Jump To “MenuName::ButtonName”)

  • Navigate to a Track (Jump To “TrackName”)

  • Navigate to a Marker (Jump To “TrackName::MarkerName”)

  • Navigate to a Story (Jump To “TrackName::Story::EntryPoint”)

  • Navigate to a Slideshow (Jump To “SlideshowName”)

  • Navigate to a Slide (Jump To “SlideshowName::SlideName”)

  • Navigate to a Script (Jump To “ScriptName”)

In addition, scripts can take advantage of GPRMs (General Parameter Register Memory) which are variables you can create to write and read values for useful things, such as keeping track of which menu viewers are on in the DVD. You’ll learn how to do just that next.

Getting Started

Adding a script to your DVD project requires only a few things:

  • A reason to script (defining the “mission” and its goals)

  • A plan for achieving the mission’s goals

  • One or more script elements (as many as it takes)

  • The necessary script commands to create those elements

Defining the Mission

Accessing the same content tracks from two different menus causes a navigation dilemma that requires a scripted solution (Figure B.1). The dilemma is that with two possible launch points for the same track, you can no longer rely on the track’s end jump (the “where do I go when I’m done” pointer) to know how to return to the same menu you started from. See the dilemma? The mission is to make it possible for the DVD to keep track of which menu called it so it can return there.

Simple logic—The “?” is the decision point for the menu return.

Figure B.1. Simple logic—The “?” is the decision point for the menu return.

Achieving the Mission’s Goals

To track the menu you were on when a button was pressed, you can define a GPRM to hold a value to define that menu, and change that value as you navigate through the DVD. You use the scripts to set and change the value. For example, you can set GPRM 0 = 1 while you are on the DVD main menu, and set GPRM 0 = 2 while you are on the alternate menu.

By doing this, you will have achieved your mission’s goal: At the end of any track’s playback (or when the viewer clicks “Menu”), the current value of GPRM 0 tells the track which menu to return to. Simple, eh?

How Many Script Elements Will It Take?

Four scripts are required to achieve your mission:

  • One to start up the process and define known values

  • One to set the Menu1 value and jump to Menu1

  • One to set the Menu2 value and jump to Menu2

  • One to determine where we began, and jump back there

Figure B.2 shows the logic steps. Upon entering Menu1, GPRM 0 is defined with the value 1 (meaning “first menu”), and it’s set to 2 when entering the alternate menu (“second menu”).

The full logic of the alternate menu scripts.

Figure B.2. The full logic of the alternate menu scripts.

When any track is selected, its end jump routes to the “where were we” script that checks the value of GPRM 0 to determine which menu to return to.

Figure B.3 shows how this project will look in DVD Studio Pro.

The logic from Figure B.2, as it looks when built in DVD Studio Pro.

Figure B.3. The logic from Figure B.2, as it looks when built in DVD Studio Pro.

To speed things along, I’ll assume you have already made a new DVD Studio Pro project and have created two menus and four tracks, as shown in Figure B.3, so you will have elements in which to connect the scripts. It’s beyond the scope of this limited article to connect all of the links in the entire project, but we will walk through the important part, which is how the scripting logic works.

Creating the First Script Element: The Startup Script

It’s easy to add a new script element (Figure B.4). You can do any of the following:

  1. Click the Add Script icon in the Toolbar.

  2. Press Command+’ (apostrophe).

  3. Choose Project > Add to Project > Script.

A script element.

Figure B.4. A script element.

You will be adding new script elements a few times as we go along, so choose the method and shortcut you like best.

Create a total of four scripts, and name them Startup Script, Set Menu1 Script, Set Menu2 Script, and Find The Source Menu Script.

To edit a name, just select the script, press the Enter key, type the new name, and press Enter again to close the name field.

Defining a Name and Partitioning GPRMs

Selecting a script icon in the Outline or Graphical view will bring up that script’s Inspector, where you can rename the GPRMs if you wish to. The GPRMs are DVD Studio Pro’s “variables”—locations where you can store and retrieve values during script operations.

In this project, the scripts will set or maintain the value of the current menu using GPRM 0.

Renaming GPRM 0, though optional, will help you remember what you are using it for.

To rename GPRM 0, reveal the GPRM 0 partition name (click the triangle next to the name), then double-click GPRM 0 and append the new name info CurrentMenu, as shown in Figure B.5. As you do this, notice there is only one partition in GPRM 0.

Renaming GPRM 0 in the Script Inspector.

Figure B.5. Renaming GPRM 0 in the Script Inspector.

Note

While there are only eight GPRMs in DVD Studio Pro, you can partition, or divide, them to create more places to store information. This is analogous to subdividing a large room into smaller rooms. While each partition is not as big as the original room, partitions can make storing and finding information easier. The Script Inspector is where the partitions are set.

Adding/Organizing Commands in the Script Tab

Once a script element has been created, it will contain one NOP (no-operation) command and will do nothing until you change that (Figure B.6). You will use the Script tab to select and organize the command lines, and you’ll use the Script Command Inspector to edit this command and others.

The Script tab with a NOP command.

Figure B.6. The Script tab with a NOP command.

Locate the Script tab in the DVD Studio Pro main window, because you will use it to confirm that the commands you create are correct and in the correct order (command order is critical in scripting). The Script tab is usually in the lower-left quadrant of the Extended or Advanced configuration.

Creating and Editing Commands

To edit a script command, click that command line in the Script tab, and then modify the selected command line using the Script Command Inspector.

Your setup for the startup script should match the settings in Figure B.7. This command will store a known initial value in GPRM 0, and it is good scripting practice. Keep in mind that “GPRM 0” is the name of the variable, while “0” is the value we are storing in that variable.

The Setup script clears GPRM 0 by placing 0 into it.

Figure B.7. The Setup script clears GPRM 0 by placing 0 into it.

To manipulate the value of a GPRM, use the Set GPRM command to clear the value in GPRM 0. In script-speak, that’s “mov GPRM 0, (immediate) 0”. I know it looks a little weird, but that’s proper.

Adding a New Script Command

Once we have set the value, we need a command to jump us from the script back into the normal DVD navigation flow, or we will be stuck in the script and at a dead end. In the Script tab, add a new command line by clicking the + button (Figure B.8). (This button always adds a command at the bottom of the command list.)

Click the + button to add a new command.

Figure B.8. Click the + button to add a new command.

We will modify this new command line to make a jump to the Set Menu1 script and begin the DVD playback. Refer to Figure B.9 for the proper command syntax to create this new script command line.

The Jump command after the setup.

Figure B.9. The Jump command after the setup.

Select Jump from the Command pop-up menu, then choose the destination from the Jump To pop-up. Figure B.10 shows what the Startup script will look like in the Script tab.

The completed Startup script.

Figure B.10. The completed Startup script.

Scripts that Set the Menu Values

There are two scripts that set (or reset) the value in GPRM 0 to tell us which menu we were on last. You’ll program each one to set the proper value, and then jump to the proper menu.

Figure B.11 shows the first command line for the Set Menu1 script, which sets GPRM 0 to 1 when we jump to the Main Menu (Menu 1). Figure B.12 shows the second command line, the jump to the menu itself.

First, set GPRM 0 to 1 to identify Menu1.

Figure B.11. First, set GPRM 0 to 1 to identify Menu1.

Then, set the Jump target to Menu1, the Main Menu.

Figure B.12. Then, set the Jump target to Menu1, the Main Menu.

When finished, your Script Editor will look like Figure B.13:

The finished Set Menu1 script.

Figure B.13. The finished Set Menu1 script.

You will author nearly the same commands for the Set Menu2 script, but remember you will set the GPRM to 2, and the Jump target to the alternate Menu2.

When finished, the Script Editor for the Set Menu2 script will look like Figure B.14.

The finished Set Menu2 script.

Figure B.14. The finished Set Menu2 script.

Adding a comment into the Comment field of each command line to identify what’s happening in each command is a good practice. If you don’t do this when you create the script, you may not remember the script’s function a few days later!

Important note

When you move from Menu1 to Menu2, you must jump through the Setup scripts, so that the current menu value in GPRM 0 is updated as you pass back and forth.

Next, the most important script of all: The one that decides which menu to go back to after a track has concluded playback (“where were we?”).

The Decision Script

It’s not actually called the “decision script,” but this important script makes the decision of which menu to return to. It reads the value of GPRM 0 and decides which menu to jump to based on that value. How can it do that?

Conditional Commands

The biggest difference in this script compared to the previous ones you created is the use of the conditional jump commands to determine which menu to go to.

The jump commands are called “conditional” because their execution is dependent on the result of a programmed comparison. You know them as “if... then...” commands.

If the comparison evaluates as “true,” then the command will execute. If not, it will proceed to the next command line in order.

This script uses two nearly identical conditional jump commands that will jump to a menu setup script, but only if the value is correct (in other words, 1 for Menu1, 2 for Menu2).

Here are the commands:

  • Jump to Menu1 if GPRM0 = 1

  • Jump to Menu2 if GPRM0 = 2

It’s that simple!

Your completed “Find the Source Menu” script should look like Figure B.15.

The decision script (“Find the Source Menu”).

Figure B.15. The decision script (“Find the Source Menu”).

Figure B.16 shows the settings for line 1 in the Script Command Inspector. (Line 2 is almost the same, but it jumps to Set Menu2 Script, and the comparison value used is 2, not 1.)

The conditional command that decides whether to jump to Menu1.

Figure B.16. The conditional command that decides whether to jump to Menu1.

That’s the magic in this script, if there is any. It’s some pretty straightforward scripting, if you evaluate the logic involved.

I haven’t covered the topics of making the button and track-end jump connections, but these are all very straightforward connections.

And remember, the more you script, the easier it gets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.114.132