GMS 2.3+ bug related to virtual_key

hi to all, according to heartbeast tutorial on 2d platform i've created two platform with a script that controls every command ( as keyboard_check...and combo of keys ). this script run at Create event and Step event of the object_command.
now i'm try to parsing an asset of 2d platform for windows on Android phone. i'm mapping virtual_key in the command script. i've an issue that i show in a short video from my pc. without virtual_key in room transition i've no issue, but adding virtual_key (even without keyboard_key actives) i've a loop of movement instruction on main character in every room transition. where i've missed or fail?


GML:
o_command create event

ricevi_comandi(); // script that handle commands

if (aspect_ratio)
{
        image_xscale = 0.5;
        image_yscale = 0.5;
        instance_create_layer(128,444, "Instances", o_joypad_R);
        instance_create_layer(0,444, "Instances", o_joypad_L);
        instance_create_layer(64,412, "Instances", o_joypad_U);
        instance_create_layer(64,476, "Instances", o_joypad_D);

        instance_create_layer(780, 476, "Instances", o_B_button);
        instance_create_layer(860, 390, "Instances", o_A_button);       
}
else    //il monitor non rispetta la proporzione dei 16:9
{
    instance_create_layer(256,864, "Instances", o_joypad_R);
    instance_create_layer(0,864, "Instances", o_joypad_L);
    instance_create_layer(128,792, "Instances", o_joypad_U);
    instance_create_layer(128,936, "Instances", o_joypad_D);

    instance_create_layer(1448, 864, "Instances", o_B_button);
    instance_create_layer(1680, 696, "Instances", o_A_button);
}
o_joypad_R, _L, _A, etc had drawGUI event with draw_self()

Code:
ricevi_comandi()

function ricevi_comandi(){
//è uno scritp senza argomenti che determina gli input da tastiera
/*
  ààààà
*/
if aspect_ratio
{
    retrospazio = keyboard_check(vk_backspace); //identifica cosa deve fare il pulsante backspace di android( la freccia che gira su sè stessa )

    /*destra = keyboard_check(vk_right);
    sinistra = keyboard_check(vk_left);
    guarda_su = keyboard_check(vk_up);
    giu = keyboard_check(vk_down);
    salto = keyboard_check_pressed(ord("X"));
    saltoalto = keyboard_check(ord("X"));
    attacco = keyboard_check_pressed(ord("Z"));

    /*destra = virtual_key_add(128, 444, 72, 72, vk_right);
    sinistra = virtual_key_add(0, 444, 72, 72, vk_left);
    guarda_su = virtual_key_add(64, 412, 72, 72, vk_up);
    giu = virtual_key_add(64, 476, 72, 72, vk_down);
    salto = virtual_key_add(860,390, 88, 88, ord("X"));
    saltoalto = virtual_key_add(860,390, 88, 88, ord("X"));
    attacco = virtual_key_add(780,476, 88, 88, ord("Z"));*/
    
    destra = keyboard_check(vk_right) or virtual_key_add(128, 444, 72, 72, vk_right);
    sinistra = keyboard_check(vk_left) or virtual_key_add(0, 444, 72, 72, vk_left);
    guarda_su = keyboard_check(vk_up) or virtual_key_add(64, 412, 72, 72, vk_up);
    giu = keyboard_check(vk_down) or virtual_key_add(64, 476, 72, 72, vk_down);
    salto = keyboard_check_pressed(ord("X")) or virtual_key_add(860,390, 88, 88, ord("X"));
    saltoalto = keyboard_check(ord("X")) or virtual_key_add(860,390, 88, 88, ord("X"));
    attacco = keyboard_check_pressed(ord("Z")) or virtual_key_add(780,476, 88, 88, ord("Z"));

//    show_debug_message("ricevi comandi");
    
}
else
{
        retrospazio = keyboard_check(vk_backspace); //identifica cosa deve fare il pulsante backspace di android( la freccia che gira su sè stessa )

        destra = keyboard_check(vk_right) or virtual_key_add(256, 864, 144, 144, vk_right);
        sinistra = keyboard_check(vk_left) or virtual_key_add(0, 864, 144, 144, vk_left);
        guarda_su = keyboard_check(vk_up) or virtual_key_add(128, 792, 144, 144, vk_up);
        giu = keyboard_check(vk_down) or virtual_key_add(128, 936, 144, 144, vk_down);
        salto = keyboard_check_pressed(vk_lshift) or virtual_key_add(1680,696, 176, 176, vk_lshift);
        saltoalto = keyboard_check(vk_lshift) or virtual_key_add(1680,696, 176, 176, vk_lshift);
        attacco = keyboard_check_pressed(ord("Z")) or virtual_key_add(1448,864, 176, 176, ord("Z"));
}

restartalastanza = keyboard_check_pressed(ord("R"));


scivolata = giu and salto; //combo di tasti in modo da utilizzarne
// il minor numero possibile
//scivolata = keyboard_check_pressed(ord("X"));
aggrapparsi = guarda_su and salto;
}
 

chamaeleon

Member
virtual_key_add() is not for testing whether a key is currently pressed at the given point in time. It is to register a key that will trigger the same event as the corresponding keyboard event. Do it once as part of the room setup, not as part of the continuous execution of steps. The function itself returns an virtual key id you are supposed to store somewhere so you can later destroy the virtual key. Since this value is likely to be interpreted as a true value in a boolean expression you I assume all your various variables get initialized to true rather than as a result of what key you press.
 
Top