This is an old revision of the document!



In LSL, most scripts sit idle until they receive some input, or detect some change in their environment. At any moment, the script is in some state, and will react to events or inputs according to some scheme defined by the programmer. However, a script can also contain two or more different states, and react differently to events or inputs depending on what state it is in.

The main state is the default state. When a script is compiled, reset or loaded, this is the state it enters by default. A script will NOT automatically re-enter the default state state_entry event when the task is rezzed or attached (even by a new owner), nor if the task is moved to another SIM, nor on SIM restart.

After the default state definition, additional state definitions may follow, which the script may use to change how and which events are handled.

default { events }

  • event events – one or more events

The default state definition.

state target { events }

  • label target – state name
  • event events – one or more events

target state definition.

state target;

  • label target – name of a state to run

When a state target; is encountered at runtime, if the current state and the target state are different:

  1. Trigger state_exit in the current state if it exists and clear the event queue.
  2. Change state to target, any listens are unregistered.
  3. Trigger state_entry in the target state if it exists.

If target state is the same as the current state, no state change occurs nor do any of the side effects.

QR Code
QR Code wiki:scripting_portal:state (generated for current page)