Should I use the input class, or my own key listener?

Discussion in 'Learning Javascript' started by MyLegGuy, May 10, 2016.

  1. MyLegGuy

    MyLegGuy Smashed Block Member

    Messages:
    3
    Likes Received:
    6
    Location:
    United States
    First Language:
    English
    Primarily Uses:
    N/A
    Right now, I'm using a bunch of if statements in the update function to check for keys.


    if (Input.isPressed("up")){
    }else if (Input.isPressed("down")){
    }else if (Input.isPressed("left")){
    } else if (Input.isPressed("right")){
    }


    The problem is, sometimes a key is missed if I tap it too fast.


    Would it be a okay if I added my own key listener instead of using the input class, or is that not okay?

    Code:
    document.addEventListener('keydown', somemethod);
     
    #1
  2. Yuuta Kirishima

    Yuuta Kirishima Software Engineer/Professional Mayonnaise Player Veteran

    Messages:
    550
    Likes Received:
    131
    Location:
    North Carolina
    First Language:
    Engilsh
    Primarily Uses:
    RMMV
    I don't foresee any issues.
     
    #2
    MyLegGuy likes this.
  3. astracat111

    astracat111 Astra Cat Veteran

    Messages:
    205
    Likes Received:
    111
    Location:
    New York City
    First Language:
    English
    I use Input.isTriggered('right') { } etc... 


    You use pages or states if you're just using coding. If you're using rpg maker mv eventing, you just use pages. 


    somefunction.prototype.update {
    if (page == 1) { set up, then page = 2 }
    if (page == 2) { if (Input.isTriggered('ok') { page = 3 } }
    if (page == 3 { process result }
    }




    Very easy, no problem with what's there, unless you need access to more keys, although that's what all of these amazing plugins that are already out are for. Depends though if you'd like to do it on your own, but you asked "do you think I would need to?" and I think the answer is no to that, you don't NEED to. You CAN if you want to practice programming. ; p
     
    Last edited by a moderator: May 15, 2016
    #3

Share This Page