Skip to content
lsl.devlsl.devLSL Dev

LlTakeControls

Looking for the current API? Open the llTakeControls reference →

Wiki description

Allows for intercepting of keyboard and mouse clicks, specifically those specified by controls, from the agent the script has permissions for.

Function notes

If accept is FALSE and pass_on is FALSE, the behavior is not intuitive. In this case, the complement of the specified controls do not generate events and do not perform their normal functions. They are effectively disabled. Certain control bits (e.g. CONTROL_ROT_LEFT) are also disabled when specified, in this case.
If accept is FALSE and pass_on is TRUE, then the specified controls do not generate events but perform their normal functions.
If accept is TRUE and pass_on is FALSE, then the specified controls generate events but do not perform their normal functions.
If accept is TRUE and pass_on is TRUE, then the specified controls generate events and perform their normal functions.

Specification

ConstantValueDescription
CONTROL_FWD0x00000001Move forward control (↑ or W)
CONTROL_BACK0x00000002Move back control (↓ or S)
CONTROL_LEFT0x00000004Move left control (← or A [← or A in mouselook])
CONTROL_RIGHT0x00000008Move right control (→ or D [→ or D in mouselook])
CONTROL_ROT_LEFT0x00000100Rotate left control (← or A)
CONTROL_ROT_RIGHT0x00000200Rotate right control (→ or D)
CONTROL_UP0x00000010Move up control (PgUp or E)
CONTROL_DOWN0x00000020Move down control (PgDn or C)
CONTROL_LBUTTON0x10000000Left mouse button control
CONTROL_ML_LBUTTON0x40000000Left mouse button control while in mouselook
(undocumented)0x02000000Avatar left rotation detected. Triggers llGetAnimation == "Turning Left"
(undocumented)0x04000000Avatar right rotation detected. Triggers llGetAnimation == "Turning Right"

Caveats

  • There appears to be no penalty for using accept = TRUE, pass_on = TRUE when there is no control event in the script (such as is used in AO's to ensure they work on no-script land)
    • There is a bug in some permissions that prevents left clicks from working in mouselook if they are set to accept = FALSE, pass_on = TRUE
  • If you sit/are sitting on the object that has taken your controls using accept = TRUE and pass_on = TRUE, then CONTROL_FWD, CONTROL_BACK, CONTROL_ROT_LEFT, and CONTROL_ROT_RIGHT will never generate events; instead these controls will only perform their normal functions.
  • if the undocumented controls 0x02000000 or 0x04000000 are taken with pass_on = FALSE, then llGetAnimation will never be "Turning Left" or "Turning Right", respectively, and those animations set by llSetAnimationOverride will never play
  • If your viewer's 'Single click on land' setting is set to 'Move to clicked point', then CONTROL_LBUTTON might not be sent to the server when taken by llTakeControls().

Examples

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }
    run_time_permissions(integer perm)
    {
        if(PERMISSION_TAKE_CONTROLS & perm)
        {
            llTakeControls(
                            CONTROL_FWD |
                            CONTROL_BACK |
                            CONTROL_LEFT |
                            CONTROL_RIGHT |
                            CONTROL_ROT_LEFT |
                            CONTROL_ROT_RIGHT |
                            CONTROL_UP |
                            CONTROL_DOWN |
                            CONTROL_LBUTTON |
                            CONTROL_ML_LBUTTON ,
                            TRUE, TRUE);
                           
        }
    }
    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);
        llOwnerSay(llList2CSV([level, edge, start, end, held, untouched]));
    }
}

Notes

If a script has taken controls, it and other scripts in the same prim will not be stopped if the Agent enters a "No Outside Scripts" parcel. This is done to keep vehicle control alive and AOs functional. This is an intentional feature. This only applies to the object containing the script - child objects in a linkset (wheels, particle emitters, in vehicles, child objects in huds, etc) will not inherit this immunity. To preserve functionality in child objects, llTakeControls must be issued in each scripted child as well.

See also: functions

See also: events

Shared wiki helpers

The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.

Template:Issues/SVC-3187

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|SVC-3187|[[llTakeControls]] overrides existing controls|type=bug}}

Template:Issues/SCR-97

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|SCR-97|[[llTakeControls]] Traps repeating event when contols are changed or permission revoked|type=bug}}

Template:LSL Function/permission

Original shared helper source (conditional wiki logic is not evaluated)
{{#if:

{{{{#if:{{#var:DEBUG_CHANNEL}}||:DEBUG_CHANNEL}}|}}

{{#vardefine:header_footnote|{{#var:header_footnote}}{{#if:{{{1|<noinclude>*</noinclude>}}}|To run this function the script must request the [[{{{1}}}]] {{#if:{{{2|}}}|or [[{{{2}}}]]}} permission with [[llRequestPermissions]]{{#ifeq:{{{grant|anyone}}}|anyone||&#32;and it must be granted by {{{grant|anyone}}}}}.}}}}

{{#vardefine:caveats|{{#var:caveats}}{{#if:{{{1|<noinclude>*</noinclude>}}}|{{PBR}}
<div style="border: 1px dotted rgba(0,0,0,0.5);">{{Collapsible_Table/Simple|title=<h5 style="margin:0;">Permissions</h5>|table-style=width:100%;|autocollapse=*|content={{!}}<div>
* Do not depend upon the auto-grant status of permissions. '''Always''' use the [[run_time_permissions]] event.
* If the script lacks {{#if:{{{2|}}}|both the permissions [[{{{1}}}]] and [[{{{2}}}]]|the permission [[{{{1}}}]]}}, the script will shout an error on {{#var:DEBUG_CHANNEL}} and the operation fails (but the script continues to run).{{#ifeq:{{{grant|anyone<noinclude>*</noinclude>}}}|anyone||
* If [[{{{1}}}]] {{#if:{{{2|}}}|or [[{{{2}}}]]}} is granted by anyone other than {{{grant|anyone}}}, then when the function is called an error will be shouted on {{#var:DEBUG_CHANNEL}}.}}
{{{caveats|}}}{{LSL Function/permission/caveat switch|{{{1}}}}}{{#if:{{{2|}}}|{{LSL Function/permission/caveat switch|{{{2}}}}}}}</div>}}</div>}}}}

{{#vardefine:also_events|{{#var:also_events}}
{{LSL DefineRow||[[run_time_permissions]]|Permission receiving event}}}}
{{#vardefine:also_functions|{{#var:also_functions}}
{{LSL DefineRow||[[llGetPermissions]]|Get the permissions granted}}
{{LSL DefineRow||[[llGetPermissionsKey]]|Get the agent who granted permissions}}
{{LSL DefineRow||[[llRequestPermissions]]|Request permissions}}}}
{{#vardefine:also_articles|{{#var:also_articles}}
{{LSL DefineRow||[[:Category:LSL Permissions/Script|Script permissions]]|}}}}

<includeonly>{{#if:{{{nc|}}}||{{#vardefine:hidden-text|{{#var:hidden-text}}
{{#if:{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||[[Category:LSL Requires Permissions]]}}
}}}}</includeonly>

}}<noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|header_footnote}}
|-
{{VarPair|caveats}}
|-
{{VarPairTable|also_events}}
|-
{{VarPairTable|also_functions}}
|-
{{VarPairTable|also_articles}}
|}
</noinclude>

Template:LSL Function/boolean

Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}{{#if:

{{#vardefine:nbdv|{{#switch:{{uc:{{{default|}}}}}|T|TRUE=true|F|FALSE=false}}}}

{{#vardefine:p_{{{1|}}}_desc|{{#if:{{{bool|}}}|{{HoverLink|boolean{{#var:lang}}|A type that can only be true or false|boolean}},}} {{{pd|}}} {{#if:{{{bool|}}}{{{pd|}}}|{{#ifeq:{{{if|}}}|*|if|{{{if|}}}}}|{{ucfirst:{{#ifeq:{{{if|}}}|*|if|{{{if|}}}}}}}}} {{#vardefineecho:TRUE|{{LSL Const{{#var:lang}}|TRUE|integer|1}}}}{{#vardefine:FALSE|{{LSL Const{{#var:lang}}|FALSE|integer|0}}}}{{#if:{{{non-zero|}}}|{{Footnote|handle=non-zero|Any value that is not zero/{{#var:FALSE}} is treated the same as {{#var:TRUE}}. This behavior should not be depended upon.|Any value that is not zero/FALSE is treated the same as TRUE. This behavior should not be depended upon.}}}}{{#ifeq:{{#var:nbdv}}|true|&#32;({{HoverText|default|default for new objects etc}})}} {{#if:{{{td|}}}|{{{td|}}}|enables}}, {{#ifeq:{{{if|}}}|*|if|{{{if|}}}}} {{#var:FALSE}}{{#ifeq:{{#var:nbdv}}|false|&#32;({{HoverText|default|default for new objects etc}})}} {{#if:{{{fd|}}}|{{{fd|}}}|disables}}}}

{{#vardefine:p_{{{1|}}}_hover|{{#if:{{{bool|}}}|boolean,}} {{#if:{{{ph|}}}|{{{ph|}}}|{{{pd|}}}}} {{#if:{{{bool|}}}{{{pd|}}}{{{ph|}}}|{{#ifeq:{{{if|}}}|*|if|{{{if|}}}}}|{{ucfirst:{{#ifeq:{{{if|}}}|*|if|{{{if|}}}}}}}}} TRUE{{#ifeq:{{#var:nbdv}}|true|&#32;(default)}} {{#if:{{{th|}}}|{{{th|}}}|{{#if:{{{td|}}}|{{{td|}}}|enables}}}}, {{#ifeq:{{{if|}}}|*|if|{{{if|}}}}} FALSE{{#ifeq:{{#var:nbdv}}|false|&#32;(default)}} {{#if:{{{fh|}}}|{{{fh|}}}|{{#if:{{{fd|}}}|{{{fd|}}}|disables}}}}}}

}}<noinclude>
{| {{Prettytable}}
|+<code><nowiki>{{{{FULLPAGENAME}}|bool|bool=*|pd=1|ph=2|default=false}}</nowiki></code>{{{{FULLPAGENAME}}|bool|bool=*|pd=1|ph=2|default=false}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_bool_desc}}
|-
{{VarPair|p_bool_hover}}
|-
{{Footnotes}}
|}
{| {{Prettytable}}
|+<code><nowiki>{{{{FULLPAGENAME}}|bool|bool=*|pd=1|ph=2|td=3|th=4|fd=5|fh=6}}</nowiki></code>{{{{FULLPAGENAME}}|bool|bool=*|pd=1|ph=2|td=3|th=4|fd=5|fh=6}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_bool_desc}}
|-
{{VarPair|p_bool_hover}}
|-
{{Footnotes}}
|}
{| {{Prettytable}}
|+<code><nowiki>{{{{FULLPAGENAME}}|bool|bool=*|if=*|non-zero=*|pd=1|ph=2|td=3|th=4|fd=5|fh=6}}</nowiki></code>{{{{FULLPAGENAME}}|bool|bool=*|if=*|non-zero=*|pd=1|ph=2|td=3|th=4|fd=5|fh=6}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_bool_desc}}
|-
{{VarPair|p_bool_hover}}
|-
{{Footnotes}}
|}
{| {{Prettytable}}
|+<code><nowiki>{{{{FULLPAGENAME}}|bool|if=when|non-zero=*|td=3|th=4|fd=5|fh=6}}</nowiki></code>{{{{FULLPAGENAME}}|bool|if=when|non-zero=*|td=3|th=4|fd=5|fh=6}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_bool_desc}}
|-
{{VarPair|p_bool_hover}}
|-
{{Footnotes}}
|}
</noinclude>
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.