GML A question about movement

Discussion in 'Programming' started by Divecko, Aug 14, 2019.

  1. Divecko

    Divecko Member

    Joined:
    Feb 12, 2018
    Posts:
    14
    I was wondering about the different ways to do player movement in GML, many of the Game Maker tutorials from YoYo like breakthrough or space rocks have you use the key down event while on forums people say to use keyboard_check(ord()) instead so I'm curious if there are differences about the practices or is it just a formatting thing?
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    833
    mainly tutorials will try to make things as obvious as possible for new users. Using an event called key down is the most obvious.
    On the forums it's a lot easier to type the explanation to just say keyboard_check.
    On top of that once you start doing a lot more programming it becomes a lot more convenient and a lot more clear to keep all your code in the same place. To the point where, at least for me, all I use is the create event, step event, and draw event (destroy event very rarely)

    Other than that there is no difference, they both do the same thing. Use whatever you prefer.
     
  3. ThePropagation

    ThePropagation Member

    Joined:
    May 16, 2017
    Posts:
    124
    if you use the key down D event for example, when it compiles it translates it into the keyboard_check(ord("D")); it's the same thing
     
  4. ThePropagation

    ThePropagation Member

    Joined:
    May 16, 2017
    Posts:
    124
    If you want more control over when events occur it's better to hard code them in instead of using events. In events you have to create conditions to make them work unless you want it to work at all times. Otherwise you can put the keyboard_check command in places where you only want it to work, giving you more control
     
  5. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,552
    And once you do even more coding, you'll want them in different places again.

    The "everything in one place" ethos that's in vogue around here starts becoming a liability past about 100 lines or so. When that happens, finding specific lines in the contiguous block becomes difficult, and excessive coupling and code repetition are common side effects of projects coded this way. I see this all the time with Step events that grow out of control in conventionally developed GM games.
     
    CloseRange likes this.
  6. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,036
    It's mostly preference. I use both depending upon what I want to do. Advantages to the events are they are easy, both to implement and to change, consistent, and you can see them immediately when you look at an object. I especially like them for objects that need only one or two methods of interaction - e.g. a button that you can only tap.

    I do not like them when you need many inputs, especially if you want those inputs to be changeable by the player. Then I prefer to make some type of input manager, and pull that into the event I need, normally in the step event.
     
  7. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    833
    that's absolutely true. I separate everything into many scripts but I meant more of in the same event not in the same block of code. That could get annoying fast.
     
  8. Divecko

    Divecko Member

    Joined:
    Feb 12, 2018
    Posts:
    14
    cool good to know, thank you guys for letting me know
     

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