GM:S 1.4 navigating a menu using a controller thumbstick

Discussion in 'Programming' started by TheNegroShoddy, Jan 10, 2019.

  1. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    394
    Hello, I'm having trouble implementing menu pointer movement for my deck editor menu. The d-pad and regular keyboard controls work fine, but I can't seem to get left thumbstick movement controls down for the menu. I did a google search on this issue and I saw that one person suggested adding a delay whenever the player moves the stick to navigate the menu. I'm experiencing a problem where if I move the thumbstick up and down in quick succession, the cursor basically ends up in the same position instantly (sorry if this isn't the best explanation).

    I should note, I tried using separate alarms last night and I had the same issue. Been stuck on this problem for two days now, so I was hoping someone here can lead me to a good solution.

    All relevant variables and code below...

    Boot Object
    GAME START
    Code:
    // Variables used to determine whether the player is moving the thumbstick and in what direction.
    global.axis_dz = 0.5; // Value to set the Deadzone to.
    gamepad_set_axis_deadzone( 0, global.axis_dz ); // Deadzone must be set to 0.5! Not 0.05!
    global.lhaxis = gamepad_axis_value( 0, gp_axislh ); // Left thumbstick horizontal movement value
    global.lvaxis = gamepad_axis_value( 0, gp_axislv ); // Left thumbstick vertical movement value
    global.ls_haxis_dir = noone; // The current horizontal direction of the left thumbstick. Set to noone by default and when the thumbstick isn't being used.
    global.ls_vaxis_dir = noone; // The current vertical direction of the left thumbstick. Set to noone by default and when the thumbstick isn't being used.
    
    // Variables used to determine when the player is actually holding the stick in a specfic direction.
    global.ls_down_hold = false;
    global.ls_up_hold = false;
    global.ls_left_hold = false;
    global.ls_right_hold = false;
    
    global.ls_down_moved = false;
    global.ls_up_moved = false;
    global.ls_left_moved = false;
    global.ls_right_moved = false;
    
    global.ls_down_time = 0;
    global.ls_up_time = 0;
    global.ls_left_time = 0;
    global.ls_right_time = 0;
    
    Game Manger Object
    STEP EVENT
    Code:
    /// Check/Change Thumbstick States (Controller)
    //  -- Left Stick Directional State --
    // Update the global.ls_haxis_dir and global.ls_vaxis_dir variables based on the direction the player moved the left thumbstick.
    // Horizontal Axis
    if ( global.lhaxis < -global.axis_dz ) { global.ls_haxis_dir = ls_dir.ls_left;  }
    if ( global.lhaxis > global.axis_dz ) { global.ls_haxis_dir = ls_dir.ls_right; }
    if ( global.lhaxis >= 0.00 && global.lhaxis <= global.axis_dz ) || ( global.lhaxis <= 0.00 && global.lhaxis >= -global.axis_dz ) { global.ls_haxis_dir = noone; }
    // Vertical Axis
    if ( global.lvaxis < -global.axis_dz ) { global.ls_vaxis_dir = ls_dir.ls_up;  }
    if ( global.lvaxis > global.axis_dz ) { global.ls_vaxis_dir = ls_dir.ls_down;  }
    if ( global.lvaxis >= 0.00 && global.lvaxis <= global.axis_dz ) || ( global.lvaxis <= 0.00 && global.lvaxis >= -global.axis_dz ) { global.ls_vaxis_dir = noone; }
    
    // -- Holding Left Stick Directional State --
    // The flag variable for the cooresponding thumbstick direction will be set to true when held in one direction for a brief period time.
    if global.ls_haxis_dir == ls_dir.ls_left
    {
        if global.ls_left_time != 11 { global.ls_left_time++; }
    }
    else
    {
        global.ls_left_time = 0;
    }
    
    if global.ls_haxis_dir == ls_dir.ls_right
    {
       if global.ls_right_time != 11 { global.ls_right_time++; }
    }
    else
    {
        global.ls_right_time = 0;
    }
    
    if global.ls_vaxis_dir == ls_dir.ls_up
    {
        if global.ls_up_time != 11 {  global.ls_up_time++; }
    }
    else
    {
        global.ls_up_time = 0;
    }
    
    if global.ls_vaxis_dir == ls_dir.ls_down
    {
       if global.ls_down_time != 11 { global.ls_down_time++; }
    }
    else
    {
        global.ls_down_time = 0;
    }
    
    
    if ( global.ls_left_time >= 1 && global.ls_left_time <= 5 ) { global.ls_left_moved = true; } else { global.ls_left_moved = false; }
    if ( global.ls_right_time >= 1 && global.ls_right_time <= 5 ) { global.ls_right_moved = true; } else { global.ls_right_moved = false; }
    if ( global.ls_up_time >= 1 && global.ls_up_time <= 5 ) { global.ls_up_moved = true; } else { global.ls_up_moved = false; }
    if ( global.ls_down_time >= 1 && global.ls_down_time <= 5 ) { global.ls_down_moved = true; } else { global.ls_down_moved = false; }
    
    
    if global.ls_left_time >= 10 { global.ls_left_hold = true; } else { global.ls_left_hold = false; }
    if global.ls_right_time >= 10 { global.ls_right_hold = true; } else { global.ls_right_hold = false; }
    if global.ls_up_time >= 10 { global.ls_up_hold = true; } else { global.ls_up_hold = false; }
    if global.ls_down_time >= 10 { global.ls_down_hold = true; } else { global.ls_down_hold = false; }
    
    
    Code:
    /// Check Thumbstick Axis (Controller)
    if global.controller_slot[0] == true // Make sure there is a controller in the first "slot"
    {
        global.lhaxis = gamepad_axis_value(0, gp_axislh );
        global.lvaxis = gamepad_axis_value(0, gp_axislv );
    }
    
    Deck editor object:
    CREATE EVENT
    Code:
    /// LS INPUT DELAY VARIABLES ___
    ls_up_input = false;
    ls_down_input = false;
    ls_up_delay = 5;
    ls_down_delay = 5;
    ls_up_delay_enable = false;
    ls_down_delay_enable = false;
    
    STEP EVENT
    Code:
    /// Deck Navigation
        if ( keyboard_check_pressed( global.up_key ) || gamepad_button_check_pressed( 0, gp_padu ) ||  global.up_button_hold == true || ls_up_input == true ||
           up_key_hold == true ) && deck_position != 1
        {
            deck_position--;
    
            if ls_up_input == true { ls_up_input = false; }
        }
    
        if ( keyboard_check_pressed( global.down_key )  || gamepad_button_check_pressed( 0, gp_padd ) || global.down_button_hold == true || ls_down_input == true ||
            down_key_hold == true ) && deck_position != max_deck_slots
        if deck_position != deck_list_size // Make sure the player can't scroll down past the number of deck cards that are listed
        {
            deck_position++;
    
            if ls_down_input == true { ls_down_input = false; }
        }
    
    
    Code:
    /// LS INPUT DELAY TIMER
    //
    if ls_down_delay < 0 { ls_down_delay = 0; }
    if ls_up_delay < 0 { ls_up_delay = 0; }
    
    //
    if ( global.ls_up_moved == true || global.ls_up_hold == true ) && ls_up_delay_enable == false
    {
        ls_up_delay_enable = true;
    }
    
    if ( global.ls_down_moved == true || global.ls_down_hold == true ) && ls_down_delay_enable == false
    {
        ls_down_delay_enable = true;
    }
    
    //
    if ls_down_delay_enable == true
    {
        if ls_down_delay != 0 { ls_down_delay--; }
        if ls_down_delay == 0 { ls_down_input = true; ls_down_delay_enable = false; ls_down_delay = 5; }
    }
    
    if ls_up_delay_enable == true
    {
        if ls_up_delay != 0 { ls_up_delay--; }
        if ls_up_delay == 0 { ls_up_input = true; ls_up_delay_enable = false; ls_up_delay = 5; }
    }
    Note: ls_moved variables indicate when the stick is just moved briefly, whereas ls_hold variables is for when the stick is moved in a direction for an extended period of time. Think of it as distinguishing between a quick button press and a button being held.
     
    Last edited: Jan 10, 2019
  2. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    394
    BUMP
    Still having trouble with this issue. Any help would be appreciated. If need be, I can provide video to show the issue.
     
  3. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    394
    Here is a video of the issue:
     
  4. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    394
    BUMP
    Still can't seem to fix this issue. Could really use some help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice