llGetGameControlModeAxes

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

Returns the semantic (mode-dependent) axis values of id for the current game_control input.
Returns a list of float values whose length and meaning depend on the mode returned by llGetGameControlMode. The list is empty when no game-control data is available for id.

• key id avatar UUID

Specification

Where the axes parameter of the game_control event reports the raw gamepad sticks and triggers, this function reports the axes the viewer derived from them for the current mode: reordered, combined (the two triggers become one axis) and remapped according to the user's bindings.

For GAME_CONTROL_MODE_AVATAR, GAME_CONTROL_MODE_MOUSELOOK and GAME_CONTROL_MODE_CAPTIVE the list has 5 elements, each in the range [-1.0, 1.0]:

IndexNameMeaning
0AXIS_STRAFESideways movement
1AXIS_ADVANCEForward/back movement
2AXIS_TURNBody yaw
3AXIS_LOOKCamera pitch
4AXIS_RISESum of up/down movement inputs

For GAME_CONTROL_MODE_FLYCAM the list has 7 elements, each in the range [-1.0, 1.0]:

IndexNameMeaning
0FLYCAM_AXIS_TRUCKCamera sideways
1FLYCAM_AXIS_DOLLYCamera forward/back
2FLYCAM_AXIS_PANCamera yaw
3FLYCAM_AXIS_TILTCamera pitch
4FLYCAM_AXIS_BOOMCamera up/down
5FLYCAM_AXIS_ROLLCamera roll
6FLYCAM_AXIS_ZOOMCamera zoom

For GAME_CONTROL_MODE_CURSOR the list has 6 elements:

IndexNameMeaningRange
0CURSOR_DXCursor horizontal motion[-1.0, 1.0]
1CURSOR_DYCursor vertical motion[-1.0, 1.0]
2CURSOR_PXCursor position, pixels, X[0.0, width]
3CURSOR_PYCursor position, pixels, Y[0.0, height]
4CURSOR_NXCursor position, normalized, X[0.0, 1.0]
5CURSOR_NYCursor position, normalized, Y[0.0, 1.0]

CURSOR_PX/CURSOR_PY are measured within the rectangle the cursor is allowed to move in: <0, 0> is its upper-left corner. CURSOR_NX/CURSOR_NY are the same position normalized to that rectangle. CURSOR mode has no turn/look slot: turning and looking still work, they are simply not mirrored here because those slots carry cursor position instead.

Constant Value
GAME_CONTROL_AXIS_LEFTX 0x00000000
GAME_CONTROL_AXIS_LEFTY 0x00000001
GAME_CONTROL_AXIS_RIGHTX 0x00000002
GAME_CONTROL_AXIS_RIGHTY 0x00000003
GAME_CONTROL_AXIS_TRIGGERLEFT 0x00000004
GAME_CONTROL_AXIS_TRIGGERRIGHT 0x00000005

Caveats

  • Only meaningful inside a game_control event: the values are 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 an empty list when the script has no game-control snapshot for id, for example when called outside of a game_control event.
  • Game-control input is only delivered to scripts which have been granted PERMISSION_GAME_CONTROL by id.
  • The length of the list depends on the mode and may grow in the future. Do not read the list from the end, do not use negative indexes, and do not assume its length; check llGetGameControlMode and index from the front.
  • Unlike the game_control event's axes list, CURSOR_PX and CURSOR_PY are not restricted to [-1.0, 1.0]: they are pixel values.
  • Several directional buttons are folded into these axes (for example the D-pad contributes to AXIS_ADVANCE and AXIS_STRAFE) while also appearing in llGetGameControlModeButtons; reacting to both will double-count the input. In CURSOR mode the D-pad is not folded into the axes.
  • If enabled at the client, keyboard avatar movement may also be translated into game-control input.

Examples

default
{
    game_control(key id, integer button_levels, list axes)
    {
        integer mode = llGetGameControlMode(id);
        list mode_axes = llGetGameControlModeAxes(id);
        if (mode_axes == [])
            return;

        if (mode == GAME_CONTROL_MODE_AVATAR
            || mode == GAME_CONTROL_MODE_MOUSELOOK
            || mode == GAME_CONTROL_MODE_CAPTIVE)
        {
            float strafe  = llList2Float(mode_axes, 0);
            float advance = llList2Float(mode_axes, 1);
            float rise    = llList2Float(mode_axes, 4);
            llOwnerSay("move: " + (string)llList2Vector(
                [<strafe, advance, rise>], 0));
        }
        else if (mode == GAME_CONTROL_MODE_CURSOR)
        {
            llOwnerSay("cursor at <"
                + (string)llList2Float(mode_axes, 4) + ", "
                + (string)llList2Float(mode_axes, 5) + "> (normalized)");
        }
    }
}

Notes

The semantic axes are supplied by the viewer in the GameControlData message. Older viewers that only send the deprecated GameControlInput message provide raw axes through the game_control event but no semantic axes, so this function returns an empty list for them.

See Also

Events

•  game_control

Functions

•  llGetGameControlMode Current game-control mode
•  llGetGameControlModeButtons Semantic button bitfield for the current mode

Articles

LSL Game Control Beta

Deep Notes

Signature

function list llGetGameControlModeAxes( key id );