GM:S 1.4 [SOLVED] Movement being interrupted by other buttons

Discussion in 'Programming' started by Andrew R. C. Beck, Sep 12, 2019.

  1. Andrew R. C. Beck

    Andrew R. C. Beck Member

    Joined:
    May 3, 2019
    Posts:
    34
    Howdydiddly all! I am having an issue in which the user controlling a ship should be able to move left and right as they wish whilst maybe using other buttons, but everytime another button is pressed as well as the left or right move keys, the movement is interrupted until they press move again :S

    Here is the control code:

    Step:

    Code:
    
    //Play True / False//
    if (global.play = true)
       {
    //-----//
    //Mouse / Keyboard//
    //-----//
    if (global.m_or_k = true)
       {
       xPos = mouse_x;
       }
    else
    if (global.m_or_k = false)
       {
       xPos = x;
       }
    //----------//
    //Controls//
    //----------//
    //Movement//
    //-----//
    //if (global.m_or_k = false)
       {
       if (keyboard_key = global_variables.mov_left)
          {
          if (xPos > 504)
             {
             x -= global.spd_1;
             }
          }
       if (keyboard_key = global_variables.mov_right)
          {
          if (xPos < 1496)
             {
             x += global.spd_1;
             }
          }   
       }
    //Launch//
    //-----//
    if (keyboard_check_pressed(global_variables.launch))
       {
       if (instance_number(projectile_obj) = 0)
           {
           ball = instance_create((x + 25),(y - 150),projectile_obj);
           with (ball)
                {
                vspeed = -global.spd_2;
                }
           }
    //       else
    //       {
    //       exit;
    //       }
       }
    //-----//
    //Bounce//
    //-----//
    if (place_meeting ( x + 20, y, projectile_obj))
       {
       with (projectile_obj)
            {
            x += 1;
            }
       }
    if (place_meeting ( x - 20, y, projectile_obj))
       {
       with (projectile_obj)
            {
            x -= 1;
            }
       }
    //-----//
    //Boundaries//
    //-----//
    if (global.m_or_k = true)
       {
       if (mouse_x >= 504 && mouse_x <= 1496)
          {
          x = mouse_x;
          }
       else
       if (mouse_x < 504)
          {
          xPos = 504;
          }
       else
       if (mouse_x > 1496)
          {
          xPos = 1496;
          }
       else
          {
          xPos = x;
          }
       }
    //-----//
       }
    //-----//
    //Win//
    //-----//
    if (global.win = true)
       {
       y -= 10;
       with (projectile_obj)
            {
            instance_destroy();
            }
       }
       
    if ((y + 125) <= 0)
       {
       audio_stop_all()
       if (global.gm == 1)
          {
          if (global.cur_lvl == global.lvl_fin_st)
             {
             global.lvl_fin_st +=1;
             }     
          }
          else
          if (global.gm == 2)
          {
          if (global.cur_lvl == global.lvl_fin_tl)
             {
             global.lvl_fin_tl +=1;
             } 
          }
       scr_savegame(1);
       room_goto(1);
       with (main_menu_obj)
            {
            if (global.gm = 1)
               {
               menu = 10;
               }
               else
               {
               menu = 11;
               }
            }
       }
    //-----//
    //Lose//
    //-----//
    if (global.lose = true)
    &&
    (!alarm_get(1))
       {
       audio_play_sound(explode_snd ,1, false);
       effect_create_above(ef_explosion, x, y + 10, 10, c_blue);
       alarm_set(1, room_speed);
       with (projectile_obj)
            {
            instance_destroy();
            }
       }
    
    Any help to stop this interruption would be much appreciated! :D
     
  2. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    430
    I would tidy this by using enums and states, enabling you to break it down and make changes or detect erroneous code.
    There are a few places where could use if..else..if rather than if..if
     
    Andrew R. C. Beck likes this.
  3. Andrew R. C. Beck

    Andrew R. C. Beck Member

    Joined:
    May 3, 2019
    Posts:
    34
    I can't say as I have much knowledge with them though I am slowly learning hehe ^_^ Thank you for the suggestion!

    Also, I know what the issue was XD I was using keyboard_key instead of keyboard_check XD
     

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