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
- Every script starts in the
defaultstate, and each state has its own handlers - Changing state fires
state_exitand thenstate_entry, and removes listeners and sensors from the old state - To stop receiving an event, change to a state without that handler, or remove its source with
llListenRemove,llSensorRemoveorllSetTimerEvent(0.0) - Resetting, running state and memory of scripts are covered under Scripts
- Every script starts in the
- Timers: each script has one timer, firing the
timerevent. Timers, sleeping and clocks are covered under Time Changesto 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 asllDetectedKeyread each one by index, and only inside that event
Sensorsscan a cone around the object for avatars or objects, once or repeatedly
Functions and events
event | state_entry() |
event | state_exit() |
event | on_rez(integer start_param) |
event | changed(integer changes) |
void | llSensor(string name, key id, integer type, float radius, float arc) |
event | sensor(integer num_detected) |
event | no_sensor() |
key | llDetectedKey(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
event | state_entry()Triggered immediately whenever a new state is entered (including at script start). It is always the first event handled. |
event | state_exit()Triggered when the state command is used to transition out of the current state. Handled before entering the new state's state_entry. |
event | on_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. |
event | changed(integer changes)Triggered when various properties of the object change. The parameter changes is a bitfield of CHANGED_* flags. |
void | llSensor(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. |
void | llSensorRepeat(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. |
void | llSensorRemove()Removes the periodic sensor previously configured by llSensorRepeat. |
event | sensor(integer num_detected)Triggered when objects matching constraints of llSensor or llSensorRepeat are successfully detected. Passes num_detected, representing the number of detected targets. |
event | no_sensor()Triggered when active sensors (from llSensor or llSensorRepeat) complete a scan without finding any matching targets. |
Additional
- Time — timers, delays and clocks
llSetTimerEvent— 0.0 stops furthertimereventsllSleep— the script is inactive during this timellMinEventDelay— minimum delay between events being handledllGetTime,llResetTime,llGetAndResetTime— elapsed script timellGetUnixTime,llGetTimestamp,llGetDate,llGetWallclock,llGetGMTclock— real-world clocks
- Scripts — resetting and controlling scripts
llResetScript,llResetOtherScript— reset this or another scriptllSetScriptState,llGetScriptState— stop, start and check other scripts in the primllGetScriptName— the script’s own name
changed— the changes bitfield (all flags)CHANGED_INVENTORY— prim inventory changed by someone with modify rightsCHANGED_LINK— number of prims or seated avatars changedCHANGED_OWNER— the object changed ownersCHANGED_REGION— the object changed regionsCHANGED_TELEPORT— the avatar this object is attached to teleported
- Detected functions —
llDetectedKey,llDetectedName,llDetectedOwner,llDetectedGroup,llDetectedPos,llDetectedRot,llDetectedVel,llDetectedLinkNumber(touches and collisions),llDetectedGrab(touches only)llDetectedType— bitfield of types (DetectType)AGENT— an avatarACTIVE— physical objects and agentsPASSIVE— non-physical objectsSCRIPTED— has at least one active script
- Common event sources
touch_start,collision_start,control— input and physicslisten,link_message,http_request— communicationsdataserver— requested data returned to the scriptrun_time_permissions— an agent granted or denied permissions
- Script health (see Scripts)
llGetFreeMemory,llGetUsedMemory— free and used script memoryllScriptProfiler—PROFILE_SCRIPT_MEMORYtracks peak memory while activellGetSimStats— region statistics such asSIM_STAT_SCRIPT_MS(script time per frame) andSIM_STAT_SCRIPT_EPS(script events per second)llGetRegionFPS,llGetRegionTimeDilation— region performancellGetEnergy— remaining physics energy of the objectllScriptDanger— whether a position is over public or sandbox land, or land that restricts building or outside scripts
Constant groups
Section titled “Constant groups”Constant groups ChangeType 13DetectType 7ScriptProfileMode 2SimulatorStat 27
Related
Section titled “Related”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