Skip to content
lsl.devlsl.devLSL Dev

Events

LSL scripts are event driven. The script does nothing until something happens: a touch, a message, a timer, a collision. Then the matching event handler in the current state runs to completion.

Events wait in a queue while a handler runs. Keep handlers short; long work blocks every other event in the script.

There is no runtime subscription to events: a state receives the events it has handlers for. Think of each state as a set of subscriptions; changing state is how a script subscribes and unsubscribes.

Concepts

  • States
  • Timers: each script has one timer, firing the timer event. Timers, sleeping and clocks are covered under Time
  • Changes to the object: inventory, links, owner, region, teleports, shape and more
    • Test the flags with the bitwise AND operator (&)
  • Detection
    • Touch, collision, sensor and damage events can report several detections at once
    • The event’s number parameter says how many; llDetected* functions such as llDetectedKey read each one by index, and only inside that event
  • Sensors scan a cone around the object for avatars or objects, once or repeatedly

Functions and events

eventstate_entry()
eventstate_exit()
eventon_rez(integer start_param)
eventchanged(integer changes)
voidllSensor(string name, key id, integer type, float radius, float arc)
eventsensor(integer num_detected)
eventno_sensor()
keyllDetectedKey(integer number)

Event Order

Which events are called for different actions, such as attaching, rezzing, resetting or changing state, and in which order.

Events by feature

Most events belong to a feature. Start from the event index, or from the feature you are working on: input, communications, physics.

Scripting Details

eventstate_entry()
Triggered immediately whenever a new state is entered (including at script start). It is always the first event handled.
eventstate_exit()
Triggered when the state command is used to transition out of the current state. Handled before entering the new state's state_entry.
eventon_rez(integer start_param)
Triggered when the object is rezzed into the world (by a script or user). Passes start_param from the rezzing call (or 0 if rezzed from inventory). Also triggers on attachments during login or when attached from inventory.
eventchanged(integer changes)
Triggered when various properties of the object change. The parameter changes is a bitfield of CHANGED_* flags.
voidllSensor(string name, key id, integer type, float radius, float arc)
Performs a single scan from the prim's forward vector for name and id of type within radius meters and arc radians. Results trigger a sensor or no_sensor event. Passing empty filters (blank name, 0 type, or NULL_KEY id) disables that filter.
voidllSensorRepeat(string name, key id, integer type, float radius, float arc, float rate)
Sets up a repeating periodic scan every rate seconds for name and id of type within radius meters and arc radians of the forward vector. Results trigger sensor or no_sensor events.
voidllSensorRemove()
Removes the periodic sensor previously configured by llSensorRepeat.
eventsensor(integer num_detected)
Triggered when objects matching constraints of llSensor or llSensorRepeat are successfully detected. Passes num_detected, representing the number of detected targets.
eventno_sensor()
Triggered when active sensors (from llSensor or llSensorRepeat) complete a scan without finding any matching targets.

Additional

Constant groups ChangeType 13DetectType 7ScriptProfileMode 2SimulatorStat 27

See also Page defaultPage stateSL Wiki LSL StatePlanned Guide: switching event handlers with states

See also Feature ScriptsFeature TimeCategory DetectedCategory SensorCategory ScriptCategory Time

See also Page All eventsFeature InputFeature CommunicationsFeature PhysicsSL Wiki LSL EventsSL Wiki Event Order