Lingo 4.0 Tutorial: Globals
READING: Manual pages of the commands described here

Take a look at and download the starting file "PresidentialRace0.dir" and the Piano audio file. The aim is to create the behavior in the final "PresidentialRace2.dir" file.

File "PresidentialRace1.dir"

Shows the use of global variables: That's how different scripts are communicating.
Any non-keyword name is considered a variable. Variables do not need to be declared ibefore usage. Typos in variable names, therefore, can create bugs.

A variable's environment is the current execution of the handler it is used in (the area between the keywords on and end). So, by default, Director's variables are local variables. That's not very useful.
Each variable to be communicated outside the handler needs to be declared as global in every script that is using it; otherwise it is considered a new variable.

In the sample file, you need to keep two global variables, one for each presidential candidate. Count the votes and report the results. Note that also you can change the contents of any field through scripting ( member(9).text = "This and that").
& is used to concatenate strings.
&& is used to concatenate strings with a white space in between them.
Note: Some people name global variables using an initial "g", e.g., g_counter

What happens in the case of a tie between the presidential candidates? Why?
How would you fix the problem?
(Hint: random(2) is a function that returns 1 or 2 at random.)

Note that the background music stops after a while. How would you make it keep playing? How would you make it loop smoothly?

File "PresidentialRace2.dir"

To become even more interesting, in this file there is some visual feedback when you roll the mouse over a candidate. Makes use of mouseEnter and mouseLeave. When the mouse enters a sprite (that is, a channel), the cast member changes to a new one ( sprite(2).member = "Arthur2" ). Note that the cast members have been named in a meaningful way. We argue that it is better to use the names of cast members instead of their numbers in the cast library that bounds them to a particular location.

Compare the sizes of the two movies - why such a difference?

Here is another way to use sound: Smooth music is playing using
sound playFile 1, "Piano"
This work in Director but not on the web. Why? Time to check the command under "Help > Director Help". Look at the web solution in File "PresidentialRace3.dir"


Also, note that the sound does not loop. How would you make it loop?
(Hint: Check command soundbusy(1) to see what it does)


Note that some text is turned bitmapped to ensure text consistency.
(BTW, check the side effect when placing the pointer under Arthur's feet.)


 

 

Maintained By: Takis Metaxas
Last Modified: June 2, 2009