1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

keyboard_check_direct not working

Discussion in 'Programming' started by Foxis, Feb 11, 2019.

  1. Foxis

    Foxis Member

    Joined:
    Jan 17, 2019
    Posts:
    8
    i did a code and it worked fine, the event was "f5 press" and then i switched it to created (Im really noob)
    and this is my code


    (the only thing i added was if keyboard_check_direct(vkf5)
    and no errers when starting

    if keyboard_check_direct(vk_f5)
    {
    if obj_sr1.sprite_index = spr_0{
    obj_sr1.sprite_index = spr_1}

    else if obj_sr1.sprite_index = spr_1{
    obj_sr1.sprite_index = spr_2}

    else if obj_sr1.sprite_index = spr_2{
    obj_sr1.sprite_index = spr_3}

    else if obj_sr1.sprite_index = spr_3{
    obj_sr1.sprite_index = spr_4}

    else if obj_sr1.sprite_index = spr_4{
    obj_sr1.sprite_index = spr_5}

    else if obj_sr1.sprite_index = spr_5{
    obj_sr1.sprite_index = spr_6}

    else if obj_sr1.sprite_index = spr_6{
    obj_sr1.sprite_index = spr_7}

    else if obj_sr1.sprite_index = spr_7{
    obj_sr1.sprite_index = spr_8}

    else if obj_sr1.sprite_index = spr_8{
    obj_sr1.sprite_index = spr_9}

    else if obj_sr1.sprite_index = spr_9{
    obj_sr1.sprite_index = spr_0;

    if obj_sr2.sprite_index = spr_0{
    obj_sr2.sprite_index = spr_1}

    else if obj_sr2.sprite_index = spr_1{
    obj_sr2.sprite_index = spr_2}

    else if obj_sr2.sprite_index = spr_2{
    obj_sr2.sprite_index = spr_3}

    else if obj_sr2.sprite_index = spr_3{
    obj_sr2.sprite_index = spr_4}

    else if obj_sr2.sprite_index = spr_4{
    obj_sr2.sprite_index = spr_5}

    else if obj_sr2.sprite_index = spr_5{
    obj_sr2.sprite_index = spr_6}

    else if obj_sr2.sprite_index = spr_6{
    obj_sr2.sprite_index = spr_7}

    else if obj_sr2.sprite_index = spr_7{
    obj_sr2.sprite_index = spr_8}

    else if obj_sr2.sprite_index = spr_8{
    obj_sr2.sprite_index = spr_9}

    else if obj_sr2.sprite_index = spr_9{
    obj_sr2.sprite_index = spr_0}}

    }
     
  2. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    305
    I'm not sure what the difference is between keyboard_check and keyboard_check_direct, but I think the function you are looking for is keyboard_check_pressed

    I'm guessing that by your code "not working" that the character is quickly cycling through its sprites. The modified code will change the sprite only when you press the key.
     
  3. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    674
    Do you mean that you changed the event from being the F5 pressed event to the Create event? If so, then you will never be able to get this to work as it will only run this code when the object gets created once, and you aren't going to be able to hit F5 at the exact same time that the object is created. If you did put this in the Create event then you need to move it to the Step event instead so that it will be called every step of the event.
     
    Foxis and SnotWaffle Studios like this.
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,591
    Why fix what wasn't broken to start with? Explain when it has become a sin to use the built-in keyboard events. This "I'm a big boy and I won't use built-in features" movement is getting out of hand in GM user circles.
     
  5. Foxis

    Foxis Member

    Joined:
    Jan 17, 2019
    Posts:
    8
    on another thread i posted i asked how to get key inputs when the program is minimized, and i got an answer to use that. This "I'm a necessery person and i will not comment a necessery comment, i will just fill it with ****" is getting out of hand.
    but for real, dont assume things when you dont know anything, grow up.

    thanks i switched it to step.
     
  6. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    390
    In this case based on his other thread Foxis wants to detect keys when the window is not in focus, so events don't suffice.
     

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