llGetGameControlModeButtons

From Second Life Wiki
Jump to navigation Jump to search
Function: integer llGetGameControlModeButtons( key id );
0.0 Forced Delay
10.0 Energy

Returns the semantic (mode-dependent) button bitfield of id for the current game_control input.
Returns a bit field (an integer) that is a bitfield of the buttons held down, interpreted according to the mode returned by llGetGameControlMode.

• key id avatar UUID

Specification

A bit is set while the corresponding action is being held down. A semantic bit index is always identical to the canonical button index it is mapped to by default, no matter how the user has actually remapped their controller. This is the difference between this function and the button_levels parameter of the game_control event: button_levels reports the raw physical buttons, while this function reports the actions the viewer derived from them.

Canonical buttons with no action in a given mode still occupy a bit, but that bit is never set for that mode.

For GAME_CONTROL_MODE_AVATAR, GAME_CONTROL_MODE_MOUSELOOK, GAME_CONTROL_MODE_CAPTIVE and GAME_CONTROL_MODE_CURSOR:

BitDefault buttonAction
0GAME_CONTROL_BUTTON_SOUTHJump
1GAME_CONTROL_BUTTON_EASTCrouch
2GAME_CONTROL_BUTTON_WESTToggle sit
3GAME_CONTROL_BUTTON_NORTH(unbound)
4GAME_CONTROL_BUTTON_BACKToggle mouse cursor
5GAME_CONTROL_BUTTON_GUIDEToggle speak
6GAME_CONTROL_BUTTON_STARTToggle mouselook
7GAME_CONTROL_BUTTON_LEFTSTICK(unbound)
8GAME_CONTROL_BUTTON_RIGHTSTICKToggle flycam
9GAME_CONTROL_BUTTON_LEFTSHOULDERMouse click left (MOUSELOOK and CURSOR only)
10GAME_CONTROL_BUTTON_RIGHTSHOULDERMouse click right (MOUSELOOK and CURSOR only)
11GAME_CONTROL_BUTTON_DPAD_UPAdvance forward
12GAME_CONTROL_BUTTON_DPAD_DOWNAdvance back
13GAME_CONTROL_BUTTON_DPAD_LEFTStrafe left
14GAME_CONTROL_BUTTON_DPAD_RIGHTStrafe right
15-31 (unbound)

For GAME_CONTROL_MODE_FLYCAM:

BitDefault buttonAction
0GAME_CONTROL_BUTTON_SOUTHZoom out
1GAME_CONTROL_BUTTON_EASTPan right
2GAME_CONTROL_BUTTON_WESTPan left
3GAME_CONTROL_BUTTON_NORTHZoom in
4GAME_CONTROL_BUTTON_BACKToggle AltZoom
5GAME_CONTROL_BUTTON_GUIDE(unbound)
6GAME_CONTROL_BUTTON_STARTToggle follow
7GAME_CONTROL_BUTTON_LEFTSTICKReset
8GAME_CONTROL_BUTTON_RIGHTSTICKToggle flycam
9GAME_CONTROL_BUTTON_LEFTSHOULDERRoll counter-clockwise
10GAME_CONTROL_BUTTON_RIGHTSHOULDERRoll clockwise
11GAME_CONTROL_BUTTON_DPAD_UPDolly forward
12GAME_CONTROL_BUTTON_DPAD_DOWNDolly back
13GAME_CONTROL_BUTTON_DPAD_LEFTTruck left
14GAME_CONTROL_BUTTON_DPAD_RIGHTTruck right
15-31 (unbound)

Constant Value
GAME_CONTROL_BUTTON_SOUTH 0x00000001
GAME_CONTROL_BUTTON_A 0x00000001
GAME_CONTROL_BUTTON_EAST 0x00000002
GAME_CONTROL_BUTTON_B 0x00000002
GAME_CONTROL_BUTTON_WEST 0x00000004
GAME_CONTROL_BUTTON_X 0x00000004
GAME_CONTROL_BUTTON_NORTH 0x00000008
GAME_CONTROL_BUTTON_Y 0x00000008
GAME_CONTROL_BUTTON_BACK 0x00000010
GAME_CONTROL_BUTTON_GUIDE 0x00000020
GAME_CONTROL_BUTTON_START 0x00000040
GAME_CONTROL_BUTTON_LEFTSTICK 0x00000080
GAME_CONTROL_BUTTON_RIGHTSTICK 0x00000100
GAME_CONTROL_BUTTON_LEFTSHOULDER 0x00000200
GAME_CONTROL_BUTTON_RIGHTSHOULDER 0x00000400
GAME_CONTROL_BUTTON_DPAD_UP 0x00000800
GAME_CONTROL_BUTTON_DPAD_DOWN 0x00001000
GAME_CONTROL_BUTTON_DPAD_LEFT 0x00002000
GAME_CONTROL_BUTTON_DPAD_RIGHT 0x00004000
GAME_CONTROL_BUTTON_MISC1 0x00008000
GAME_CONTROL_BUTTON_PADDLE1 0x00010000
GAME_CONTROL_BUTTON_PADDLE2 0x00020000
GAME_CONTROL_BUTTON_PADDLE3 0x00040000
GAME_CONTROL_BUTTON_PADDLE4 0x00080000
GAME_CONTROL_BUTTON_TOUCHPAD 0x00100000

Caveats

  • Only meaningful inside a game_control event: the value is a snapshot taken when the event was queued, so the mode, buttons and axes read by a script are all consistent with the event being processed.
  • Returns 0 when the script has no game-control snapshot for id, for example when called outside of a game_control event. A return of 0 therefore does not prove that no buttons are held down; check llGetGameControlMode for -1 first.
  • Game-control input is only delivered to scripts which have been granted PERMISSION_GAME_CONTROL by id.
  • The meaning of every bit changes when the mode changes, so always pair this with llGetGameControlMode.
  • In most modes several directional buttons are also folded into the axes returned by llGetGameControlModeAxes; reacting to both will double-count the input.
  • Bit 31 is the sign bit of an LSL integer. Use the bit-mask constants rather than comparing against a signed value.

Examples

integer prev_buttons = 0;

default
{
    game_control(key id, integer button_levels, list axes)
    {
        integer mode = llGetGameControlMode(id);
        if (mode != GAME_CONTROL_MODE_AVATAR)
            return;

        integer buttons = llGetGameControlModeButtons(id);
        integer edges = buttons ^ prev_buttons;
        prev_buttons = buttons;

        // Bit 0 is "Jump" in AVATAR mode, whichever physical button is bound to it.
        if (edges & GAME_CONTROL_BUTTON_A)
        {
            if (buttons & GAME_CONTROL_BUTTON_A)
                llOwnerSay("jump pressed");
            else
                llOwnerSay("jump released");
        }
    }
}

Notes

The semantic button mask is supplied by the viewer in the GameControlData message. Older viewers that only send the deprecated GameControlInput message provide raw buttons through the game_control event but no semantic mask, so this function returns 0 for them.

See Also

Events

•  game_control

Functions

•  llGetGameControlMode Current game-control mode
•  llGetGameControlModeAxes Semantic axes for the current mode

Articles

LSL Game Control Beta

Deep Notes

Signature

function integer llGetGameControlModeButtons( key id );