Difference between revisions of "Game control"

From Second Life Wiki
Jump to navigation Jump to search
(Add link to info about current beta status.)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
|p1_type=key|p1_name=id|p1_desc=avatar UUID
|p1_type=key|p1_name=id|p1_desc=avatar UUID
|p2_type=integer|p2_name=button_levels|p2_desc=bitfield of buttons held down
|p2_type=integer|p2_name=button_levels|p2_desc=bitfield of buttons held down
|p3_type=integer|p3_name=button_edges|p3_desc=bitfield of buttons that have changed
|p3_type=list|p3_name=axes|p3_desc=list of axes float values in range [-1, 1]
|p4_type=list|p4_name=axes|p4_desc=list of axes values in range [-1, 1]
|event_desc='''Experimental''' event only available in some testing regions (soon).  Triggered when compatible viewer sends fresh '''GameControlInput''' message, but only for scripts on attachments or seat.
|event_desc='''Experimental''' event only available in some testing regions (soon).  Triggered when compatible viewer sends fresh '''GameControlInput''' message, but only for scripts on attachments or seat.
|constants={{LSL Constants/GameControlButtonFlags}} {{LSL Constants/GameControlAxisIndices}}
|constants={{LSL Constants/GameControlButtonFlags}} {{LSL Constants/GameControlAxisIndices}}
Line 9: Line 8:
|caveats=* If enabled at the client: unhandled keystrokes will be treated as button presses.
|caveats=* If enabled at the client: unhandled keystrokes will be treated as button presses.
* There is room for 32 buttons [bits 0 through 31] however at most only 16 buttons can be simultaneously held down at any one time.
* There is room for 32 buttons [bits 0 through 31] however at most only 16 buttons can be simultaneously held down at any one time.
* '''button_edges''' is computed using old an new '''button_levels''' between events, not between when the data arrives by network packet from the client. If the script is unable to process events fast enough then some rapid down-up or up-down edges may be lost.
* There are always 6 '''axes''' values, even when the controller device has more or less
* There are always 6 '''axes''' values, even when the controller device has more or less
** All '''axes''' elements will be in range [-1,1] except for '''GAME_CONTROL_AXIS_TRIGGERLEFT''' and '''GAME_CONTROL_AXIS_TRIGGERRIGHT''' which range [0, 1]
** All '''axes''' elements will be in range [-1,1] except for '''GAME_CONTROL_AXIS_TRIGGERLEFT''' and '''GAME_CONTROL_AXIS_TRIGGERRIGHT''' which range [0, 1]
|examples=
|examples=
<syntaxhighlight lang="lsl2">
<syntaxhighlight lang="lsl2">
integer prev_button_levels = 0;
integer print_list(string name, integer type, list data)
integer print_list(string name, integer type, list data)
{
{
Line 64: Line 63:
         llOwnerSay("Ready for game_control events");
         llOwnerSay("Ready for game_control events");
     }
     }
   
 
     game_control(key id, integer button_levels, integer button_edges, list axes)
     game_control(key id, integer button_levels, list axes)
     {
     {
        integer button_edges = button_levels ^ prev_button_levels;
        prev_button_levels = button_levels;
         string button_levels_hex = bits2nybbles(button_levels);
         string button_levels_hex = bits2nybbles(button_levels);
         string button_edges_hex = bits2nybbles(button_edges);
         string button_edges_hex = bits2nybbles(button_edges);
Line 80: Line 82:
|also_events={{LSL DefineRow||[[control]]|}}
|also_events={{LSL DefineRow||[[control]]|}}
|also_functions
|also_functions
|also_articles
|also_articles=[[LSL Game Control Beta]]
|also_footer
|also_footer
|notes
|notes

Latest revision as of 18:51, 16 January 2024

Description

Event: game_control( key id, integer button_levels, list axes ){ ; }

Experimental event only available in some testing regions (soon). Triggered when compatible viewer sends fresh GameControlInput message, but only for scripts on attachments or seat.

• key id avatar UUID
• integer button_levels bitfield of buttons held down
• list axes list of axes float values in range [-1, 1]
Constant Value
GAME_CONTROL_BUTTON_A 0x00000001
GAME_CONTROL_BUTTON_B 0x00000002
GAME_CONTROL_BUTTON_X 0x00000004
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
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

  • If enabled at the client: unhandled keystrokes will be treated as button presses.
  • There is room for 32 buttons [bits 0 through 31] however at most only 16 buttons can be simultaneously held down at any one time.
  • There are always 6 axes values, even when the controller device has more or less
    • All axes elements will be in range [-1,1] except for GAME_CONTROL_AXIS_TRIGGERLEFT and GAME_CONTROL_AXIS_TRIGGERRIGHT which range [0, 1]
All Issues ~ Search JIRA for related Bugs

Examples

integer prev_button_levels = 0;
integer print_list(string name, integer type, list data)
{
    integer data_length = llGetListLength(data);
    string text = name + " : ";
    if (data_length > 0)
    {
        integer use_comma = FALSE;
        integer i = 0;
        for (i = 0; i < data_length; i++)
        {
            if (!use_comma)
            {
                use_comma = TRUE;
            }
            else
            {
                text += ",";
            }
            if (type == TYPE_INTEGER)
            {
                integer b = (llList2Integer(data, i));
                text += (string)(b);
                llOwnerSay("pack i=" + (string)(i) + " b=" + (string)(b));
            }
            else if (type == TYPE_FLOAT)
            {
                text += (string)(llList2Float(data, i));
            }
        }
    }
    llOwnerSay(text); 
    return data_length;
}

string bits2nybbles(integer bits)
{
    integer lsn; // least significant nybble
    string nybbles = "";
    do
        nybbles = llGetSubString("0123456789ABCDEF", lsn = (bits & 0xF), lsn) + nybbles;
    while (bits = (0xfffFFFF & (bits >> 4)));
    return nybbles;
}

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

    game_control(key id, integer button_levels, list axes)
    {
        integer button_edges = button_levels ^ prev_button_levels;
        prev_button_levels = button_levels;

        string button_levels_hex = bits2nybbles(button_levels);
        string button_edges_hex = bits2nybbles(button_edges);
        llOwnerSay("game_control :");
        llOwnerSay("  button_levels=0x" + button_levels_hex);
        llOwnerSay("  button_edges=0x" + button_edges_hex);
        print_list("  axes", TYPE_FLOAT, axes);
    }
}

See Also

Events

•  control

Articles

LSL Game Control Beta

Deep Notes

Signature

event void game_control( key id, integer button_levels, list axes );