Director Manual
[] intro windows concepts tools howto lingo advanced summary resources

LINGO

In Director it is possible to manually program almost anything Director can do. The scripting language used in Director is Lingo. Lingo is a basic scripting language and is easy to master.

How does Lingo work?

First thing to know is that there are different types of Lingo-scripts:

The first kind of script, the movie script can be called to the screen pressing CRTL+SHIFT+U, or select from the menu.(!) You will see a completely empty text screen and it is up to you to fill it!

handlers


In Lingo you can define what are called 'handlers', these are actually functions and are similar like for example Javascript. An example of a Movie-script with two handlers is:


    on startMovie
      alert "Multimedia is leuk!"
    end startMovie     
  
    on stopMovie
      alert "bye bye!"
    end
  

Note:

Lingo is a case-insensitive language, so don't worry about those capital letters, although good programming would be making consistent and clear use of capital letters!

A handler always begins with on and then follows the 'event'. In this example two handlers are programmed, the things that must be done when the movie starts and the things that must be done when the movie ends. A handler always closes with the word end.

Note:

Just 'end' at the end of a handler is sufficient although you can also write 'end [handler]' which is easy when your handler becomes somewhat big.

Note:

There are a lot of system-handlers like the ones in the example above but you can also write your own.

In this example I have issued the command 'alert [string]' which gives a popup-box with the string displayed in it (very useful for debugging your code!). Another way to debug your code is too issue some 'put ' commands. In this case the message is send too the messenger window which can be shown on CRTL+M.

Another movie handler is 'on prepareMovie' which is executed before 'on startMovie' and is useful for setting starting-variables. To create a variable that is accessible for more handlers, you must create a 'global' variable. You can define a global variable anywhere outside any handler in which case it is accessible by all handlers in the same script and handlers in other scripts that include the variable. Or you can define a global variable inside a script. In this case the variable is only accessible for that handler and any other handler that also defines the variable.

Example:

global variables



    global startText
  
    on startMovie
      set startText 
      to "Multimedia is leuk!"
      alert startText
      global endText
      set endText = "bye bye!"
    end startMovie     
  
    on stopMovie
global endText alert endText end

This example is actually the same as the example before except thhat the text is now stored in two global variables. Variables in Lingo do not have a type specification, the variable gets it's type when it is first set or when it is reset. Too assign a value to a variable the following notations can be used: 'set [variable_name] to [some_string_or_other_value]' or 'set [var] = [some]' for those of you who dislike programming with a lot of words.

When a variable is reset the type is also reset, so the following code will give an error:


    set myVariable to 2  -- integer
    alert myVariable     -- error! for 2 is not an integer
  
Correct would be:

    set myVariable to 2  -- string
    alert myVariable     -- correct! since myVariable is a string
  
or

    set myVariable to '2' 
   -- integer
    alert string(myVariable) -- correct! since now the value 2 will be cast to a string
  

Lingo also has a lot of system variables which can be used at any time. System variables often consist of the word 'the' followed by the variable. this can be confusing when debugging if you forget the word 'the' since Lingo will create a new local variable. Some System variables are 'the mouseV' (vertical position of the mouse-pointer), 'the mouseH' (horizontal position of the mouse-pointer), 'the shiftDown' (boolean presenting wheter the 'shift' key is pressed or not), 'the key' (the last key pressed) etcà One very important system-variable is 'the frame' which denotes the current frame of the movie and is much used in frame-scripts.

In addition to movie-scripts you can also use score-scripts. These are either frame-scripts, sprite-scripts or behaviors (which are actually sprite or score-scripts but more on bahaviours later).

Frame-scripts are defined in the first line of the upper-part of the score and can be accessed by double-clicking on a cell.

frame scripts


In a frame-script code is programmed which will only be executed when the play-back-head of the movie is at the frame. Handlers that can be used in a frame script are: 'on prepareFrame', 'on enterFrame', 'on exitFrame' and there effects are obvious.

Note:

You can also use these handlers in movie-scripts accept that then they count for EVERY frame in your movie!

Example:


    on exitFrame
     go to the frame 
    end exitFrame
  

or


    on exitFrame
      go to marker("the end")
    end exitFrame
  

In both examples the 'go to' command is issued. This command expects a integer value which represent a frame (the first frame is number 1 and so on). In the first example the go to commands goes to 'the frame' which is the frame the script is in so the play-back head enters the same frame again and thus a loop is created! In the second example the play-back head goes to the frame where the marker "the end" is defined.

A sprite script is also a score-script. Sprite-scripts can be called from the menu at sprites or cast members.

sprite script


Sprites can have multiple scripts on them as long as there aren't more then one of each handler. Hanlders often used in sprite scripts are: 'on beginSprite', 'on endSprite', 'on mouseOver', 'on mouseLeave', 'on mouseDown', 'on mouseUp' etc.

Example:

sprite script



    on mouseUp
      alert nextSentence()
    end mouseUp
  
    on nextSentence
       set myNounList to ["Multimedia", "Assisting", 
           "College", "The manual"]
       set myVerbList to ["stays", "is, "is not",
  	 "continues to be", "will be"]
       set myProverbList to ["stupid.", "fun.", 
  	 "exhilarating.", "too great too put in words."']
       set myRandomSentence to
  	      myNounList[random(count(myNounList))] &&
                myVerbList[random(count(myVerbList))] &&   
                myProverbList[random(count(myProverbList))]
    return myRandomSentence
    end nextSentence
  

Note:

I've written a small handler in this sprite script which generates random sentences from the given lists.

Note:

To let a handler return some value just put a return command somewhere along with the variable too be returned.

Note:

When a return command is issued the rest of the script is NOT omitted. The same holds for the 'go to'-command and others. You can also alter your sprites and cast members run-time with Lingo. To select a cast member type 'member "[yourMember]" of castlib "[yourCastLib]" or member [A_Number]', to select a sprite just use 'sprite [yourSpriteNumber]'. You only have to specify your castlib if it isn't the internal castlib. You can either reference cast members by there name (string!) or by there place in the castlib (int!).

Sprite-scripts are often referred to as behaviors. In effect these scripts do not differ accept that behaviors can be attached to multiple sprites without being copied. So if the behviour script changes the script on all sprites with the behavior changes. In contradiction sprite-scripts are private too the sprite.

Reference:

To know more about lists in Lingo choose help lingo dictionary Lists in Director.

Reference:

To know more about cast members in Lingo choose help lingo dictionary Cast members in Director.

Reference:

To know more about sprites in Lingo choose help lingo dictionary sprites in Director.


[] intro windows concepts tools howto lingo advanced summary resources
eliens@cs.vu.nl

draft version 0.5 (12/3/2001)