How to Structure your OSDM Script Code

A tutorial by Roy/SAC

If your productions grow bigger and your script code longer, it makes sense to start structuring your code to keep things clean and organized and avoid headaches later on.

Here is how I usually structure the code for my own multi-part demos that are entirely controlled via OSDM Script.

The general idea behind this structure is to „split“ your demo into multiple „mini demos“ and keep them pretty much independent from each other. That makes it easy to add additional parts or to rearrange the oder of your existing parts. There are typically some exceptions, like the music, which does not necessarily change with every part of the demo (although it could of course).

Each part starts with the display stopped, which allows the loading and initializing of the effects that you are going to use for the part without showing any artifacts on the screen visible for the viewer of your demo. Once everything is in place you enable the display to fade in your initial setup of the part. Then you do all the things that you want to do, like moving things around fade in or out sprites or activate effects that were not needed during part loading. Once done, you stop the display followed by a NOP = 1 to let it fade-out nicely. Then you clean up house and disable all the effects that you were using for the part. You do that for all the parts and it should not happen that effects from other demo parts interfere with the currently active one and it also keeps your script code organized and structured.

FPS = 60      ;Set the Frame Rate for the Demo
PSH           ;Update Effect Values 
              ;(always good, I had some issues once where adding this command 
              ;to the script solved it. Can't remember the exacy details anymore though)
CAL = MUSIC   ;Start the Music 
;LEA = MUSIC  ;Enable, if you created an OMA archive with multiple tunes
;IDN = 0      ;Select the first tune in OMA archive
STP = DISPLAY ;Stop the Display for a moment to avoid artifacts being displayed during initialization
NOP = 1       ;Refresh the screen, You might use NOP = 0, but I had OSDM crash sometimes when I did it

JSR = 1       ;Calls the routine that initializes all settings 
              ;especially hidden sprites entirely, which can't be done via the OSDM interface
              ;I typically set the alpha to "1", but "1" is not making them entirely invisible

;Part 1
JSR = 2       ;Start a demo part

...           ;add sub routines for each part of the demo
;Part X     
;JSR  = X

;Quit Demo via Scroller Ctrl Code ^Q1
JSR = 99     ;Quit the demo

END          ;End the Script Control
LAB = 1
   CAL = SPRITE    ;Turn Sprite Effect On (make sure that it is also enabled on the "Main" settings screen in OSDM)
   LEA = SPRITE    ;Activate Script Control for Sprite Effect
   IDN = 0         ;Select Sprite 1
   MVA = 0         ;Set Alpha of Sprite to 0 (Invisible)
   IDN = 1
   MVA = 0
   IDN = 2
   MVA = 0
   IDN = 3
   MVA = 0
   IDN = 4
   MVA = 0
   IDN = 5
   MVA = 0
   IDN = 6
   MVA = 0  
   IDN = 7        ;Select Sprite 8
   MVA = 0        ;Set Alpha to 0
   STP = SPRITE   ;Stop Sprite Effect

   ;Stop Scroller 8 With Quit Ctrl Code
   IDN = 7        ;Select Scroll Text ID: 8
   MVS = 0        ;Set Speed to 0 (Stop the Scroller)
;Part 1
;Example Demo Part
LAB = 2

   ;Initialize Effect
   IDN = 0
   MVA = 254       ;Set desired Alpha Value of Sprite, 254 makes it Opaque
   CAL = MASK      ;Enable other effects, such as the MASK Effect

   ;Fade in the Display
   NOP = 1        ;NOP = 1 makes sure that the screen is faded in nicely
                  ;Make sure that you enabled "Allow to fade display in and out" in the "Display" Tab in OSDM

   ...            ;Do whatever you want to do

  ;Fade Out       
   STP = DISPLAY ;Let the Screen Fade out again
   NOP = 1

   ;Clean Up
   LEA = SPRITE   ;Hide the Sprite and Stop all Effects that were enabled for this Demo part
   IDN = 0
   MVA = 0
   STP = MASK   
;Quit Demo ("      ^P3^Q1" Code in Text Scroller)
LAB = 99
  CAL = DISPLAY ;Enable Display to prevent crash during Quit
  NOP = 1
  CAL = SCROLL  ;Enable Scroll Effect
  LEA = SCROLL  ;Enable Script Control for Scroller
  IDN = 7       ;Select Scroll Text ID: 8 
  MVS = -5      ;Set Speed to scroll forward (remember, it was stopped via the Init Routine eaerlier)
  NOP = 3       ;Wait .. Demo will quit shortly and disable everything


 tutorials/how_to_structure_your_osdm_script_code.txt · Zuletzt geändert: 2013/04/05 08:33 (Externe Bearbeitung)
Falls nicht anders bezeichnet ist der Inhalt dieses Wikis unter der folgenden Lizenz veröffentlicht:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Driven by DokuWiki