These are utility functions which may prove useful in a variety of situations.

Functions




function Random (ExclusiveUpperBound)

Returns a pseudo-random number.

Parameters

ExclusiveUpperBound Exclusive upper bound; the random number will range from zero to this number minus 1.
Returns

Random number in the range from 0 to upper minus 1.

Example
// select a greeting randomly
switch random(4) {
case 0: "Hi."
case 1: "Hello."
case 2: "Howdy."
case 3: "Whassup?"
}




function RandomRange (LowerBound, UpperBound)

Returns a random number in an inclusive range. For example, a random number in the range (5, 7) will return 5, 6, or 7.

Parameters

LowerBound Inclusive lower bound of range.

UpperBound Inclusive upper bound of range.
Returns

Random number. (Or, if the lower bound exceeds the upper, zero.)




function LastCycleLength

Used to determine the length of the last interpreter cycle. This is handy for figuring out if your scripts are running slower than they should. For instance, if you've created a rain effect and it's bogging down game performance, you could reduce the number of raindrops.

Returns

Returns the length of the last interpreter cycle.




function QueueScript (WhichScript, WhichObject, SortPriority)

Inserts a script into the interpreter's drawing queue with the given priority.

Parameters

WhichScript Index of the script to queue.

WhichObject Index of the object to use as the queued script's active object.

SortPriority Priority to give the script within the drawing queue. Values 0..255 will cause the script to be called after objects with Z values less than SortPriority are drawn, and before objects with Z values greater than SortPriority are drawn.




function FindDistance (x1, y1, x2, y2)

Calculates the distance between two points.

Parameters

x1 x-position of first point.

y1 y-position of first point.

x2 x-position of second point.

y2 y-position of second point.
Returns

Distance between two the points.

Example
print "Bob and Fred are approximately %d pixels apart.",
     findDistance(Bob.positionX, Bob.positionY,
          Fred.positionX, Fred.positionY);




function FindDirection (X, Y)

Calculates the direction a line segment points. This is useful for finding out which direction an object must turn to face toward another point.

Parameters

X x-position.

Y y-position.
Returns

Direction number (0 to 11)