Scripts
This page is about the script itself rather than what it does in the world: how it starts and resets, how it learns the parameters it was rezzed with, how it controls other scripts in the same prim or loads scripts into other prims, and how much memory it uses. The events that drive a script are covered under Events, and its timer and clocks under Time.
Concepts for scripts
- Every script starts in the
defaultstate;state_entryis always the first event handled- Changing state fires
state_exitbefore the new state’sstate_entry
- Changing state fires
- A script can reset itself or another script in the prim
- On reset, the current event is exited, global variables return to their defaults, timers (including repeating sensors) are cleared, listeners are removed, the event queue is cleared and the
defaultstate becomes active llResetScriptalso releases any granted URLs- Resetting another script that is not running has no effect, even after it is set running again
- On reset, the current event is exited, global variables return to their defaults, timers (including repeating sensors) are cleared, listeners are removed, the event queue is cleared and the
- An object learns how it was rezzed from
on_rez, the start parameter and, forllRezObjectWithParams, a start string- When an agent rezzed the object, the start parameter is 0 and the start string is empty
- Other scripts in the same prim can be stopped and started and
checked. A script can read its own name- A script that hit a run-time error, or was added with
llGiveInventory, cannot be started this way
- A script that hit a run-time error, or was added with
- A script can be copied into another prim, running or not, if the owner can modify that prim and it has set a matching PIN
- Memory
- A script can read its
usedandfreememory and itslimit, and set the limit up to 64k, the default for new scripts - The
profilerrecords the peak memory used while it is active, with up to a 100x performance penalty to the script - Scripts compiled to LSO always report 16KB used and cannot be profiled for memory
- A script can read its
Script functions and events
event | state_entry() |
event | state_exit() |
event | on_rez(integer start_param) |
void | llResetScript() |
void | llResetOtherScript(string script) |
integer | llGetStartParameter() |
string | llGetStartString() |
string | llGetScriptName() |
void | llSetScriptState(string script, integer running) |
integer | llGetScriptState(string script) |
void | llRemoteLoadScriptPin(key target, string script, integer pin, integer running, integer start_param) |
void | llSetRemoteScriptAccessPin(integer pin) |
integer | llGetUsedMemory() |
integer | llGetFreeMemory() |
integer | llGetMemoryLimit() |
integer | llSetMemoryLimit(integer limit) |
void | llScriptProfiler(integer flags) |
integer | llGetSPMaxMemory() |
Scripts as inventory items
Scripts are items in a prim’s inventory. Listing, giving and removing them is covered under Inventory.
Script functions in detail
Life cycle
Section titled “Life cycle”event | state_entry()Triggered 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 moves out of the current state, before the new state’s state_entry |
event | on_rez(integer start_param)Triggered when the object is rezzed, with start_param from the rezzing call. Also triggers on attachments at login or when attached from inventory |
void | llResetScript()Resets the script |
void | llResetOtherScript(string script)Resets script name in the prim. If the script is not running, this call has no effect |
integer | llGetStartParameter()Returns the start parameter passed to the object when it was rezzed, or 0 if an agent rezzed it |
string | llGetStartString()Returns the string passed to the root prim with REZ_PARAM_STRING in llRezObjectWithParams, or an empty string if an agent rezzed it |
string | llGetScriptName()Returns the name of the script that called this function |
Other scripts
Section titled “Other scripts”void | llSetScriptState(string script, integer running)Set the running state of the script name. The script stops when its time slice ends, so a script stopping itself may run a little further |
integer | llGetScriptState(string script)Returns TRUE if the named script in the prim is running |
void | llRemoteLoadScriptPin(key target, string script, integer pin, integer running, integer start_param)Copy script name into target and set to running with a start_param only if target’s PIN matches pin. Only works if the script owner can modify target; a script of the same name there is silently replaced |
void | llSetRemoteScriptAccessPin(integer pin)Sets this prim’s PIN for llRemoteLoadScriptPin. A PIN of 0 disables remote loading |
Memory
Section titled “Memory”integer | llGetUsedMemory()Returns the bytes of memory the script uses. Does not require llScriptProfiler |
integer | llGetFreeMemory()Returns the free bytes between the script’s current use and its memory limit |
integer | llGetMemoryLimit()Get the maximum memory a script can use |
integer | llSetMemoryLimit(integer limit)Request limit bytes to be reserved for this script. The limit cannot be set lower than the memory already in use. Returns TRUE on success |
void | llScriptProfiler(integer flags)Enables or disables the scripts profiling state, with PROFILE_SCRIPT_MEMORY or PROFILE_NONE |
integer | llGetSPMaxMemory()Returns the peak memory in bytes used while the profiler was last active |
Additional
llScriptProfiler— The profile state resets toPROFILE_NONEwhen the object is rezzed, derezzed or changes regions, when the region restarts, or when the script is reset or taken to or from inventoryllSetScriptState— A paused script’s memory is reset if it is re-rezzed, moved to another region or in a region during a restartllRemoteLoadScriptPin— start_param only lasts until the script is reset. It silently fails on an attachment worn by another userllGetObjectDetails— Script statistics for any object or avatarOBJECT_SCRIPT_MEMORY— Allocated script memory, or its upper limit, in bytesOBJECT_SCRIPT_TIME— Average script CPU time per frameOBJECT_RUNNING_SCRIPT_COUNT— Number of running scripts
llGetSimStats— Region statistics such asSIM_STAT_SCRIPT_MS(script time per frame) andSIM_STAT_SCRIPT_EPS(script events per second)llGetEnergy— Remaining physics energy of the objectllGetFreeURLs— HTTP URLs still available to the owner or regionllScriptDanger— Whether a position is over public or sandbox land, or land that restricts building or outside scriptsllSetTimerEvent,llSleep,llGetTime— See Time
Constant groups
Section titled “Constant groups”Constant groups ScriptProfileMode 2
Related
Section titled “Related”See also Feature EventsFeature TimeFeature InventoryCategory ScriptPage state
Adapted from the Second Life Wiki pages LlResetScript (revision 1216200, 2024-02-16), LlResetOtherScript (revision 1194467, 2015-01-22), LlSetScriptState (revision 1194424, 2015-01-22), LlRemoteLoadScriptPin (revision 1208255, 2019-04-02), LlSetMemoryLimit (revision 1194459, 2015-01-22), LlGetMemoryLimit (revision 1194206, 2015-01-22), LlScriptProfiler (revision 1196004, 2015-03-31), LlGetUsedMemory (revision 1218635, 2026-02-18), LlGetFreeMemory (revision 1218634, 2026-02-18) and LlGetScriptName (revision 1194254, 2015-01-22), including the transcluded Template:LSL Function/inventory (revision 1191151, 2014-06-07), Template:Issues/SVC-1853 (revision 1155886, 2011-10-18), Template:LSL Function/boolean (revision 1185613, 2013-12-24), Template:Issues/SVC-3321 (revision 118342, 2008-10-26), Template:LSL Function/give (revision 1212353, 2022-09-24) and Template:Issues/SVC-388 (revision 955732, 2010-07-03); history, by Second Life Wiki contributors, under CC BY-SA 3.0. Last wiki edit: .