Difference between revisions of "Game control"

From Second Life Wiki
Jump to navigation Jump to search
(Initial docs for experimental game_control event)
 
(change game_control signature to use bitfields instead of lists for buttons)
Line 1: Line 1:
{{LSL_Event|event_id=40|event_delay|event=game_control
{{LSL_Event|event_id=40|event_delay|event=game_control
|p1_type=key|p1_name=id|p1_desc=avatar UUID
|p1_type=key|p1_name=id|p1_desc=avatar UUID
|p2_type=list|p2_name=buttons_edge_down|p2_desc=list of buttons indices that transitioned to '''down''' state
|p2_type=list|p2_name=button_levels|p2_desc=bitfield of buttons held down
|p3_type=list|p3_name=buttons_edge_up|p3_desc=list of buttons indices that transitioned to '''up''' state
|p3_type=list|p3_name=button_edges|p3_desc=bitfield of buttons that have changed
|p4_type=list|p4_name=buttons_down|p4_desc=list of buttons indices that are currently pressed '''down'''
|p4_type=list|p4_name=axes|p4_desc=list of axes values in range [-1, 1]
|p5_type=list|p5_name=axes|p5_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/GameControlInputs}}
|constants={{LSL_Constants/GameControlInputs}}
|spec
|spec
|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 are 256 possible button indices however the '''buttons_down''' list is capped to a maximum length of 16.
* 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.
* '''buttons_edge_down''' and '''buttons_edge_up''' are computed using old an new '''buttons_down''' values when the event runs. If the script is unable to process events fast enough then some down-up and up-down edge pairs may cancel out and not register.
* '''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]

Revision as of 17:02, 18 October 2023

Description

Event: game_control( key id, list button_levels, list button_edges, 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
• list button_levels bitfield of buttons held down
• list button_edges bitfield of buttons that have changed
• list axes list of axes values in range [-1, 1]

Template:LSL Constants/GameControlInputs

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.
  • 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
    • 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

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);
}

default
{
    state_entry()
    {
        llOwnerSay("attach or sit");
    }
    game_control(key id, list buttons_down_edge, list buttons_up_edge, list buttons_down, list axes)
    {
        llOwnerSay("game_control :");
        print_list("  edge_down", TYPE_INTEGER, buttons_down_edge);
        print_list("  edge_up", TYPE_INTEGER, buttons_up_edge);
        print_list("  down", TYPE_INTEGER, buttons_down);
        print_list("  axes", TYPE_FLOAT, axes);
    }
}

See Also

Events

•  control

Deep Notes

Signature

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