Creating Simple Scripts - an introduction
Creating Simple Scripts
Creating a script is a straightforward enough process, and adding a script to your project is as simple as clicking on the ‘Add Script’ button in your DVDSP task bar. When you do, a small brown tile will be added to the graphical view, and you can start adding lines to that script using the script editor window. Click on the script icon to activate it. Please note, the scripts shown below are for example only and should not be copied as they will not always work in all situations. They are illustrative of how to create a script, rather than to do a specific scripting job.

In the script editor you will see the word ‘Nop’ on the left hand side below all of the buttons. This means ‘No Operation’ and is in effect an empty command. When you click on it to highlight the line, the script property inspector changes and you can access the drop down menu of possible actions. Note also that the Nop takes up a single command - you don’t have many to play with (well, plenty for most things, but don’t get carried away) so you want to try to write scripts in as economical manner as possible.

The main commands used in the vast majority of scripts are the ‘Jump’ command and the ‘Set GPRM’ command. If you are using subtitles or multiple audio tracks then the ‘Set System Stream’ command will also be important. Well deal with these three first.
Jump
This command will let you set navigational jumps from different places within your DVD structure. It is often (although not always) used with an ‘If’ statement. For example ‘Jump to the main menu IF you came from track 2′. Of course, the syntax isn’t written like that, but this is a more friendly translation. When you select the ‘Jump’ option from the first menu, the property inspector window changes to allow you to set the parameters necessary:

From these two images you can see that all you do to select the ‘jump target’ is use the drop down selector window and keep following the arrow prompts until you end up where you want the target to be.
In the example here I am clearly heading into ‘Menu 1′, but you can equally select any other element in your DVD, including other scripts.

Notice that when you do select a target that your script window shows the correct syntax for your choice, and that in most cases you’ll also see an arrow appear in the graphical view, illustrating that you have made a connection between the script and some other element.

When you jump to a menu you get some other options, such as GPRM based buttons, loop point selection and the control for the ‘If’ statement, should you require one. Note that the ‘If’ command is closely linked to values held in GPRMs.

What this means is that you can place a value into a memory slot (a GPRM) and use it later on in some way to help establish more complex navigation around your DVD. Hwever, the ‘If’ condition does not have to depend on just one thing - you can compare against other GPRM values, if there are any, against SPRM values (these are values automatically generated by your DVD player - system parameters - which you can read off and use), you can set ‘immediate’ values (a simple number of your choice) or you can rely on ’special values’ (these are typically used when you need the internal reference to a particular menu or track instead of a numerical value that you have specified). The ‘Jump target’ value is a little more tricky to explain, but essentially allows you to specify the value of any item in your disc structure, each of which will be assigned an internal value by your DVD player. You can, if you are not careful, end up in an unintentional loop with this one, and for the purpose of this tutorial we’ll stick to the more simple choices.

Here you can see that the script line has changed to read ‘jump to menu 1 if the value in GPRM 0 is equal to 2′.
So how do we get values into different GPRMs? Let’s add a line to the script by using the ‘+’ button and getting another ‘Nop’ line. We can click and drag that to be above the ‘Jump’ line, making it the first line in our script.
The Set GPRM command
This is possibly the most straightforward of the lot, and is best thought of as moving a value into a space. The value can be any number you like (up to the maximum of 65535), or you can use the other attributes. A good example of using the ‘Set GPRM’ command is to put in the value of a menu button number so that you can get back to it later on. You would do this by selecting a specific SPRM - SPRM8 in this case, which automatically records the value of the last button your viewer selected on whatever menu they were last on. You only get the button number, mind you, not the button AND the menu. You then use the drop down menus to select what you want to do with this value. In our example we want to move it into the GPRM, so we select the ‘Mov’ option. We could, however, do some mathematical stuff with the number (it *is* a number after all) and choose to add to it, subtract, divide, use it as part of a modulus operation or use it in a bitwise operation (you need to brush up on your binary maths if you haven’t already done so!). There is also an option to swap it with a different GPRM value, or use it to generate a random number (’Ran’). However, we just want to do a simple ‘Mov’.

Once again, you have the option of using a compare command, too - you might only ‘Mov’ the value *if* something else is true, for example. Instead of ‘Mov’ you could also ‘Add’ the value to an empty GPRM, although don’t do this if you already have a vlaue in there as it will, well… add to it!
When you set up the source type you’l see a familiar box - in this example, we are using the ‘Immediate’ value and typing in ‘2′ (there’s nothing special about using ‘2′, we could use any number, but if I were you I’d start with logical values. A better number to have used in this tutorial would have been ‘1′, since we are setting up a jump to ‘Menu 1′ and logically that makes sense… however, we have used ‘2′.. sorry).

Now you can see the script developing. It reads as follows:
Line 1- Move ‘2′ into GPRM0
Line 2- Jump to Menu 1 If (GPRM0 = 2)
Clearly it does equal 2, so what’s the point? Well, it might not equal 2 if you have a lot of other scripts running, or are making more use of GPRM values. In a short tutorial it is not possible to put in all of the eventualities, but only to give a flavour of what is able to be achieved. We;ll add a third line now, so that it helps put this into context. What if GPRM0 didn’t equal ‘2′? Where would we go then? Simply add a new ‘Nop’ by clicking on the ‘+’ button and make sure it is on Line 3, then add a new ‘Jump’ statement. In our very simple example, I’ll jump to Track 1, but you can go anywhere, as long as it exists in your project:

Now it all reads ‘put ‘2′ into GPRM0 and jump to menu 1 if GPRM0 *is* 2. Otherwise go to track 1′
Again, I must emphasise that your values may well be different to mine, and if you do use my example then you have to understand that line 3 will never, ever take place.
Caveat 1
Scripts are ‘read’ by the DVD player a line at a time. Wherever the player can actually do something, like move a value or make a jump then it will. If you make a jump line that can happen logically (as above) then anything below that will not be read since you will have left the script to do the jump. If the line cannot be evaluated as possible then the DVD Player will move on to the next line in an effort to find something it can do. In essence, scripts are read a line at a time form the top. Jump out of them carefully, but ALWAYS make sure there is at least one jump somewhere.
GPRM based jumps and markers
You may well have spotted the option to check a box in the above screens to use a ‘GPRM Based’ jump or marker, and now be wondering what that is.
Well, this example is a very simple (and ultimately flawed) script that is serving to illustrate the process rather than do anything specific. In a more featured tutorial (many are available on this site and elsewhere) you might want your viewer to either jump to a certain chapter in a track based on a value created elsewhere, or return to a specific button on a menu, such as the one they left when going to the track (like in a scene selection menu).
For example, let’s say that your viewer has come from a menu where the first button is the ‘Go to Main Menu’ button, but the others refer to a specific chapter in that movie. Using our three commands above, and adding in a GPRM based jump we can do some pretty cool stuff. You simply point the menu buttons at the following script:

Let’s deconstruct that a little.
Line 1 is calling the value of SPRM8, which is where you get the value of the last button selected on a menu. A slight issue here is that the values begin at ‘1024′ and increment by this amount for each subsequent button. Therefore we need line 2, which divides the value by 1024 to give us a value of 1, 2, 3, etc. So far, we have got the script to save a value for the last button. Next we set up a conditional ‘Jump’ command… if the user selected button 1, they will jump to menu 1. If not they will jump to the track (line 4). However, line 4 also contains a GPRM based marker. So, if the user selected button 3 on the menu, they will go to chapter 3 on the track if you use this script.
Caveat 2
GPRM based button jumps and GPRM based markers can give you amazingly good navigation, but you must be careful. With a GPRM based button jump you cannot set a script as a pre-script to a menu, since the jump will be bypassed. (A pre-script is a set of commands to run before the menu appears). Similarly, in the example above there is an error - how would you ever go to chapter 1 on the track? These are the sort of issues that you can find yourself dealing with if you are not very careful! To sort out the chapter 1 problem, we have to add a final line to the middle of the script that subtracts ‘1′ from GPRM0 so that if the user selected button 3 (which is almost certainly going to say ‘play Ch.2′ on it), the user ends up where they expect to be. The alternative is to add a short piece of black to the start of your track and set chapter 2 marker to be at the beginning of the footage. That way button 2 will go to chapter 2 which will, in fact, be the start of the track (yes, it can get confusing, but if you are this far down the page and still reading, you’re doing OK)! The scripted solution would finally look like this:

Set System Stream
This command is actually a lot more simple than it looks. Most, if not all DVDs will have at least one audio track on them, but you might want to enable your viewers to playback the footage whilst listening to a different audio clip - another language or director’s commentary, for example. Similarly you may want to provide subtitles in different languages or for textual effects during playback. Finally, you might have gone to the trouble of adding alternative angles for your viewer to chose from. These are all ’system streams’.
Setting a system stream does depend on you having multiple streams to begin with, otherwise the script editor will record what you have set, but declare the streams as ‘empty’. Adding an additional audio file to a second audio track, or adding a subtitle file and setting the language for it will start to fill in the options in the drop down box for the property inspector.
You may have a menu which encourages your viewer to select a particular audio stream - usually by selecting a button. You can set the target for the button to go to a script which sets the correct audio stream to play back then jumps back to the menu, or simply jumps on to the track itself to begin playback… the choice there is for you to decide on.
The option in the script editor works in the same way as the last two - add a new line (or click on a ‘Nop’ statement) and choose ‘Set System Stream’. The inspector will change accordingly, and you use the tools available to make the settings you want. Note that you can set one, two or all three streams in one go, do so based on a value in a GPRM (so you could ge the last button number and use that to indicate which stream plays from your 8 audio clips) and also add a conditional statement (so only play audio4 If GPRM0 has a value of 23… however you managed to get to that).


Caveat 3
There is more than one way to ensure a particular stream plays when a user selects a button, but scripts are pretty good at this. You might consider using the button properties from your menus, for example - when creating a button you can set which streams get activated - but this might be a script to change angle once a particular chapter has played in a track, or introduce a subtitle text at a specific point according to other choices that have been made. If in doubt, keep it simple and use the button conditions, but if you are feeling adventurous, use scripts!
Conclusion
The three commands used in this tutorial are probably enough to get you working with scripts and able to do some pretty cool things. Using SPRM8 to get the last button number is very useful, but so is using SPRM7 to know what the last chapter played was. These two SPRMs will enable you to move from menus to tracks and from tracks to menus with some certain knowledge about where you were. A full list of SPRMs is available on this site here. Note that not all of them can be accessed easily and some depend on others to provide all the information you need. However, knowing the DVD Player’s parental level setting lets you set a system stream to play a particular angle, knowing the language set up lets you direct navigation to the appropriate set of menus. Having a clue which button was the last selected means you can easily get back to that button - or add 1 to it to get to the next logical button in the sequence. Setting a value into a GPRM for every menu you have got means that you always know which menu was the last to be shown to the viewer -combine that knowledge with SPRM8 and you will never wonder which menu or button they came from (or where to send them back to) again.
Scripting is incredibly powerful, as you can see with just the three commands sets outlined in this tutorial. However, not everything needs to be scripted by any means. There is usually a non-scripting method to do most things, although in many cases the alternative method is either longer to implement or less flexible in some way.
Use the information here to write your own scripts, or download some of the tutorial files from other pages on this site and start to deconstruct what has gone on. If you are an absolute beginner, don’t expect to understand how to create a video jukebox on your first go, but do look at things like GPRM based button jumps until you get more confident.
Remember, there is a limit to the number of commands a single script can hold, but if you make the last command a jump to a second script, you can carry on from there as if nothing happened! There is an almost unlimited number of scripts you can create on a single DVD, but heck… keep it simple, folks!
