Difference between revisions of "Control"

From Second Life Wiki
Jump to navigation Jump to search
m (Added information about CONTROL_FWD and CONTROL_BACK being triggered together after a teleport, and how to fix the bug.)
(25 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{LSL_Event
{{LSL_Event
|inject-2={{Issues/SCR-97}}{{Issues/SVC-3187}}{{LSL Function/avatar|id|}}
|event_id=15|event_delay=0.05|event=control
|event_id=15|event_delay=0.05|event=control
|p1_type=key|p1_name=id|p1_desc
|p1_type=key|p1_name=id|p1_desc
|p2_type=integer|p2_name=level|p2_desc
|p2_type=integer|p2_subtype=bit_field|p2_name=level|p2_desc=bitfield of CONTROL_* flags, non-zero while one or more keys is being held down.
|p3_type=integer|p3_name=edge|p3_desc
|p3_type=integer|p3_subtype=bit_field|p3_name=edge|p3_desc=bitfield of CONTROL_* flags, non-zero when one or more keys have been just pressed or released.
|event_desc=Result of [[llTakeControls]] library function call and user input.
|event_desc=Result of [[llTakeControls]] library function call and user input.
|constants={{LSL Constants/Controls}}
|constants={{LSL Constants/Controls}}
|spec
|spec
|caveats
|caveats=*[[CONTROL_ROT_LEFT]] and [[CONTROL_ROT_RIGHT]] can be triggered when an object is selected or edited. If the user is running Viewer 2.0 and later, [[llGetAgentInfo]] will have [[AGENT_AUTOPILOT]] set in this case. 
|examples=<pre>
**Autopilot control events can continue for a short time after AGENT_AUTOPILOT drops.
default
*The 'levels' and 'edges' of the control() event both receive ([[CONTROL_FWD]] + [[CONTROL_BACK]]) (value 3) after teleport, effecting scripts that use this combination for faster movement. Calling llTakeControls() again after a llSleep(3) will filter this out.
 
|examples=<source lang="lsl2">default
{
{
     state_entry()
     state_entry()
Line 30: Line 33:
                             CONTROL_LBUTTON |
                             CONTROL_LBUTTON |
                             CONTROL_ML_LBUTTON |
                             CONTROL_ML_LBUTTON |
                             0, TRUE, TRUE);
                             0, TRUE, FALSE);
                            // | 0 is for edit convenience,
                            // it does not change the mask.
         }
         }
     }
     }
Line 38: Line 43:
         integer end = ~level & edge;
         integer end = ~level & edge;
         integer held = level & ~edge;
         integer held = level & ~edge;
         integer unheld = ~(level | edge);
         integer untouched = ~(level | edge);
         llOwnerSay(llList2CSV([level, edge, start, end, held, unheld]));
         llOwnerSay(llList2CSV([level, edge, start, end, held, untouched]));
     }
     }
}
}</source>
</pre>
|helpers
|helpers
|also_header
|also_header
Line 54: Line 58:
|notes=[[llGetRot]] in [[mouselook]] for an attachment returns the angle the avatar is looking in.
|notes=[[llGetRot]] in [[mouselook]] for an attachment returns the angle the avatar is looking in.


If [[llMinEventDelay]] is set to at least double this events delay, then this event will treat the [[llMinEventDelay]] as if it were half; in other words, this event can trigger twice as often as other events if the [[llMinEventDelay]] is greater than 0.1
There are some bugs when you put two scripts in the same prim and call LlTakeControls(), the '''id''' may not be the intended one. See [http://jira.secondlife.com/browse/SVC-3187 SVC-3187].
 
My tests determined that the key returned when an agent control is caught is not the key for that agent, but is the object owner's key. If more then one script is used in the same object to hold permissions for multiple agents simultaneously, control may be triggered in all scripts but there is no way to know which agent actually caused the trigger. [[User:Anthony Reisman|Anthony Reisman]] 09:59, 14 February 2007 (PST)
 
|mode
|mode
|issues
|cat1=Controls
|cat1=Controls
|cat2
|cat2

Revision as of 08:49, 21 October 2020

Description

! Event: control( key id, integer level, integer edge ){ ; }
15 Event ID
0.05 Delay

Result of llTakeControls library function call and user input.

• key id avatar UUID
• integer level bitfield of CONTROL_* flags, non-zero while one or more keys is being held down.
• integer edge bitfield of CONTROL_* flags, non-zero when one or more keys have been just pressed or released.
Constant Value Description
CONTROL_FWD 0x00000001 Move forward control ( or W)
CONTROL_BACK 0x00000002 Move back control ( or S)
CONTROL_LEFT 0x00000004 Move left control (⇧ Shift- or ⇧ Shift-A [ or A in mouselook])
CONTROL_RIGHT 0x00000008 Move right control (⇧ Shift- or ⇧ Shift-D [ or D in mouselook])
CONTROL_ROT_LEFT 0x00000100 Rotate left control ( or A)
CONTROL_ROT_RIGHT 0x00000200 Rotate right control ( or D)
CONTROL_UP 0x00000010 Move up control (PgUp or E)
CONTROL_DOWN 0x00000020 Move down control (PgDn or C)
CONTROL_LBUTTON 0x10000000 Left mouse button control
CONTROL_ML_LBUTTON 0x40000000 Left mouse button control while in mouselook
(undocumented) 0x02000000 Avatar left rotation detected. Triggers llGetAnimation == "Turning Left"
(undocumented) 0x04000000 Avatar right rotation detected. Triggers llGetAnimation == "Turning Right"

Caveats

  • CONTROL_ROT_LEFT and CONTROL_ROT_RIGHT can be triggered when an object is selected or edited. If the user is running Viewer 2.0 and later, llGetAgentInfo will have AGENT_AUTOPILOT set in this case.
    • Autopilot control events can continue for a short time after AGENT_AUTOPILOT drops.
  • The 'levels' and 'edges' of the control() event both receive (CONTROL_FWD + CONTROL_BACK) (value 3) after teleport, effecting scripts that use this combination for faster movement. Calling llTakeControls() again after a llSleep(3) will filter this out.

Important Issues

~ All Issues ~ Search JIRA for related Bugs
   llTakeControls Traps repeating event when contols are changed or permission revoked
   llTakeControls overrides existing controls

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 |
                            0, TRUE, FALSE);
                            // | 0 is for edit convenience,
                            // it does not change the mask.
        }
    }
    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

llGetRot in mouselook for an attachment returns the angle the avatar is looking in.

There are some bugs when you put two scripts in the same prim and call LlTakeControls(), the id may not be the intended one. See SVC-3187.

See Also

Deep Notes

Issues

All Issues

~ Search JIRA for related Issues
   llTakeControls Traps repeating event when contols are changed or permission revoked
   llTakeControls overrides existing controls

Signature

event void control( key id, integer level, integer edge );