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 run the routine that you name.

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.
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, otherwise the alteration will run forever and can never be removed. (ex: set a distance or a destination)
The above paragraph is not entirely true anymore. The remove command can remove alterations by type or by _all. For example:
remove from {spritename} where type=rotation
remove from {spritename} where type=_all

Changing Sprite Properties

You can change just about any sprite property. Do this with an 'update' command:
update sprite {spritename} where {property}={value} and {property2}={value2} [etc]
Inside a routine, you must use and to separate values that you are updating.

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:
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'.

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.