Routines

Routines do the work of coordinating sprites in a game.

Event Handlers

When an alteration completes, it calls an event handler called completion. The completion handler will the routine you name.
editable

Changing Alterations

The primary purpose of routines is to change sprite alterations. You can do this 2 ways:
Adding alterations to a sprite:
insert into {spritename} where alt={altname}
Removing alterations from a sprite
remove from {spritename} where alt={altname}
For efficiency you can also use a "sub" to define an alteration inside a routine instruction:
insert into {spritename} where alt=(sub create rotation where speed=700 distance=530 end)
Alterations defined in routines can be anonymous - they don't need to be named. However it is your responsibility to include an end point as part of the alteration else the alteration will run forever and can never be removed. (ex: set a distance or a destination)

Change Sprite Properties

You can change just about any sprite value that you can set when a sprite is created. Do this with an 'update' command:
update sprite {spritename} where {property}={value} and {property2}={value2} [etc]

Many More Things to Change

Please see the reference guide for a list of many more things that you can change from inside a routine.

Calling Routines with Parameters

You can call a routine from inside another routine 2 ways. The first is a simple call on a line:
MyRoutineName(11,22,33)
run routine MyRoutineName where repeat=4
run routine MyRoutineName(11,22,33) where repeat=4 // Not supported yet
The () indicates that that is a routine name. You can list parameters between () that can be used by the routine. To reference parameters use arg.1 arg.2 arg.3 etc

NOTE: Parameters lists inside () cannot themselves contain a ( or a ) Therefore, save your values to a temporary variable using 'var'.
editable

Calling Routines with Data Parameters

You can pass data to routines with data created using "create data". To see how this is done visit the data page.

Calling Routines with Repeat

You can call a routine multiple times with 'repeat'
run routine MyRoutine where repeat=7
That would run the routine 7 times.
You can also repeat with a data object. This has the effect of running the routine once until the data list reaches the last value. It is up to you to advance the data pointer so that the routine does not run forever on one value.
editable