Lingo basics

-- exercise V, March 15, 2000 --
 

   
   
Contents  

I. Controlling navigation.
II. Text input.
III. Animation by cast member shifting.
IV. Rubberbanding.
V. Autonomous time-based behavior.

   
   
       
   


Autonomous Alien Relations. They interact every ten seconds if left to themselves.

   
   
Introduction  

Not all programs are purely reactive. It is often the case that the interface changes based on internal computations or developments in the state of processes that the interface communicates with. This module looks at interfaces that exhibit autonomous behavior based on elapsed time.

   
   
Structure  

The movie builds on the Alien Relations Primer from the first module. It has the same structure, with a looping start frame and four sections of score-based animation.

This movie, however, keeps track of how much time has passed since the last animation was performed. When that time exceeds a limit, and the movie is waiting in the start frame, it randomly picks one of the four animation sequences and jumps to it.

Elapsed time is calculated as the difference between the time now and the time when it started counting. The start time for counting is reset each time the playback head leaves an animation and jumps back to the start frame.

   
   
Relevant Lingo  

Lingo has a couple of functions that return the time passed since the computer was started. the ticks gives the time in 1/60 of a second. the milliSeconds gives the same time in milliseconds.

random(X) returns a random value between 1 and X.

If you want to select different actions depending on a value, the case structure is more elegant than a nested if-else:

case (randomValue) of
  1: go to frame "argument"
  2: go to frame "love"
  3: go to frame "hate"
end case

on idle is a handler that you typically place in a movie script. It runs whenever no other handlers run. A useful place to put continuous checks of the elapsed time since you started counting.

global. If you want to calculate elapsed time since a certain starting time, you need to store the starting time in a way that makes it accessible to other handlers. The word global is used to declare a variable that becomes shared between handlers. All handlers that want to use the shared variable must declare it as global.

on startMovie
  global startTicks
  set startTicks = the ticks
end startMovie

on idle
  global startTicks
  set ticksElapsed = the ticks - startTicks
  if (ticksElapsed > 10*60) then
    randomAnimation
  end if
end idle
   
   
Why not a timeout?  

You might have found out about the Lingo support for timeout handling: the timeoutScript, the timeoutLength etc. Those functions would in fact have been very appropriate to use for this exercise. The reason for recommending an on idle handler and the basic time functions above is that it is a more general and flexible approach.