llGetGameControlMode

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

Returns the game-control mode the viewer of id was in when the current game_control input was generated.
Returns an integer that is one of the GAME_CONTROL_MODE_* constants, or -1 if no game-control data is available for id.

• key id avatar UUID

Specification

The mode determines how the viewer maps the physical gamepad onto semantic (mode-dependent) axes and buttons, which are read with llGetGameControlModeAxes and llGetGameControlModeButtons.

Constant Value Meaning
GAME_CONTROL_MODE_AVATAR 0 Normal third-person avatar control.
GAME_CONTROL_MODE_MOUSELOOK 1 Avatar is in mouselook.
GAME_CONTROL_MODE_FLYCAM 2 Flycam (camera) control.
GAME_CONTROL_MODE_CAPTIVE 3 Avatar is sitting, or controls have been taken.
GAME_CONTROL_MODE_CURSOR 4 The left stick drives the on-screen mouse cursor.

Caveats

  • Only meaningful inside a game_control event: the value is a snapshot taken when the event was queued, so that the mode, buttons and axes read by a script are all consistent with the event being processed.
  • Returns -1 when the script has no game-control snapshot for id, for example when called outside of a game_control event, or after the queued events for that agent have all been consumed.
  • Game-control input is only delivered to scripts which have been granted PERMISSION_GAME_CONTROL by id.
  • The mode is chosen by the viewer, not by the script. It can change at any time (for example when the user enters mouselook or stands up), and a mode change on its own is enough to trigger a game_control event.
  • New modes may be added in the future; do not assume the list above is exhaustive.

Examples

default
{
    state_entry()
    {
        llOwnerSay("Ready for game_control events");
    }

    game_control(key id, integer button_levels, list axes)
    {
        integer mode = llGetGameControlMode(id);
        if (mode == GAME_CONTROL_MODE_FLYCAM)
        {
            // 7 semantic axes: truck, dolly, pan, tilt, boom, roll, zoom
            llOwnerSay("flycam axes: " + llList2CSV(llGetGameControlModeAxes(id)));
        }
        else if (mode == GAME_CONTROL_MODE_CURSOR)
        {
            list a = llGetGameControlModeAxes(id);
            llOwnerSay("cursor pixels: <" + (string)llList2Float(a, 2)
                + ", " + (string)llList2Float(a, 3) + ">");
        }
        else if (mode != -1)
        {
            // 5 semantic axes: strafe, advance, turn, look, rise
            llOwnerSay("movement axes: " + llList2CSV(llGetGameControlModeAxes(id)));
        }
    }
}

Notes

The mode and the semantic data are supplied by the viewer in the GameControlData message. Older viewers that only send the deprecated GameControlInput message still fire game_control events, but provide no mode, so this function returns -1 for them.

See Also

Events

•  game_control

Functions

•  llGetGameControlModeAxes Semantic axes for the current mode
•  llGetGameControlModeButtons Semantic button bitfield for the current mode

Articles

LSL Game Control Beta

Deep Notes

Signature

function integer llGetGameControlMode( key id );