Skip to content
lsl.devlsl.devLSL Dev

llGetGameControlModeButtons

function
Function syntax
integer llGetGameControlModeButtons(
  1. key id// UUID of the avatar whose game-controller state to query.
);
Returns
integer
Energy
10

Returns the semantic (mode-dependent) button bitfield of id for the current game_control input. Bit meanings vary by mode; use the GAME_CONTROL_BUTTON_* constants as masks.

Returns an integer of the buttons held down, interpreted according to the mode returned by llGetGameControlMode.

How to use
integer result = llGetGameControlModeButtons(NULL_KEY);

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 and GAME_CONTROL_MODE_CAPTIVE:

BitName
0GAME_CONTROL_BUTTON_JUMP
1GAME_CONTROL_BUTTON_CROUCH
2GAME_CONTROL_BUTTON_SIT
3(unbound)
4GAME_CONTROL_BUTTON_TOGGLE_CURSOR
5GAME_CONTROL_BUTTON_TOGGLE_SPEAK
6GAME_CONTROL_BUTTON_TOGGLE_MOUSELOOK
7(unbound)
8GAME_CONTROL_BUTTON_TOGGLE_FLYCAM
9(unbound)
10(unbound)
11GAME_CONTROL_BUTTON_ADVANCE_FORWARD
12GAME_CONTROL_BUTTON_ADVANCE_BACK
13GAME_CONTROL_BUTTON_STRAFE_LEFT
14GAME_CONTROL_BUTTON_STRAFE_RIGHT
15–31(unbound)

For GAME_CONTROL_MODE_MOUSELOOK:

BitName
0GAME_CONTROL_BUTTON_JUMP
1GAME_CONTROL_BUTTON_CROUCH
2GAME_CONTROL_BUTTON_SIT
3(unbound)
4GAME_CONTROL_BUTTON_TOGGLE_CURSOR
5GAME_CONTROL_BUTTON_TOGGLE_SPEAK
6GAME_CONTROL_BUTTON_TOGGLE_MOUSELOOK
7(unbound)
8GAME_CONTROL_BUTTON_TOGGLE_FLYCAM
9GAME_CONTROL_BUTTON_CURSOR_BUTTON_LEFT
10GAME_CONTROL_BUTTON_CURSOR_BUTTON_RIGHT
11GAME_CONTROL_BUTTON_ADVANCE_FORWARD
12GAME_CONTROL_BUTTON_ADVANCE_BACK
13GAME_CONTROL_BUTTON_STRAFE_LEFT
14GAME_CONTROL_BUTTON_STRAFE_RIGHT
15–31(unbound)

For GAME_CONTROL_MODE_CURSOR:

BitName
0GAME_CONTROL_BUTTON_JUMP
1GAME_CONTROL_BUTTON_CROUCH
2GAME_CONTROL_BUTTON_SIT
3(unbound)
4GAME_CONTROL_BUTTON_TOGGLE_CURSOR
5GAME_CONTROL_BUTTON_TOGGLE_SPEAK
6GAME_CONTROL_BUTTON_TOGGLE_MOUSELOOK
7(unbound)
8GAME_CONTROL_BUTTON_TOGGLE_FLYCAM
9GAME_CONTROL_BUTTON_CURSOR_BUTTON_LEFT
10GAME_CONTROL_BUTTON_CURSOR_BUTTON_RIGHT
11GAME_CONTROL_BUTTON_ADVANCE_FORWARD
12GAME_CONTROL_BUTTON_ADVANCE_BACK
13GAME_CONTROL_BUTTON_STRAFE_LEFT
14GAME_CONTROL_BUTTON_STRAFE_RIGHT
15–31(unbound)

For GAME_CONTROL_MODE_FLYCAM:

BitName
0GAME_CONTROL_BUTTON_ZOOM_OUT
1GAME_CONTROL_BUTTON_PAN_RIGHT
2GAME_CONTROL_BUTTON_PAN_LEFT
3GAME_CONTROL_BUTTON_ZOOM_IN
4GAME_CONTROL_BUTTON_TOGGLE_ALT_ZOOM
5(unbound)
6GAME_CONTROL_BUTTON_TOGGLE_FOLLOW
7GAME_CONTROL_BUTTON_RESET
8GAME_CONTROL_BUTTON_TOGGLE_FLYCAM
9GAME_CONTROL_BUTTON_ROLL_CCW
10GAME_CONTROL_BUTTON_ROLL_CW
11GAME_CONTROL_BUTTON_DOLLY_FORWARD
12GAME_CONTROL_BUTTON_DOLLY_BACK
13GAME_CONTROL_BUTTON_TRUCK_LEFT
14GAME_CONTROL_BUTTON_TRUCK_RIGHT
15–31(unbound)
  • 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.
Example 1
8 collapsed lines
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;
11 collapsed lines
// 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");
}
}
}

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.

LSL Game Control Beta

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.