GML A question about movement

D

Divecko

Guest
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?
 

CloseRange

Member
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.
 
T

ThePropagation

Guest
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
 
T

ThePropagation

Guest
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
 

FrostyCat

Redemption Seeker
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.
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.
 

samspade

Member
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.
 

CloseRange

Member
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.
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.
 
Top