Tips for Creating a Script

A common error is to assign an eventIn to an eventOut directly by name (see below). It looks correct, but it doesn't work because an eventIn in a script is actually a function (with the same name as the event). This function contains data elements (the value and time arguments). The eventOut, on the other hand, is itself a data element.

In the following example, value is the data element of the startFloat function. This variable is assigned to the outFloat eventOut.

/////////////////////// FIELDS ///////////////////////////////// 

eventIn  SFFloat startFloat
eventOut SFFloat outFloat

 

/////////////////////// BEHAVIOR /////////////////////////////////

function startFloat(value, time)
{
   outFloat = startFloat;   // WRONG!!!
   outFloat = value;       // Correct.
}

Jump to: