GMS 2 Event / object driven

I have been using Game maker for a while. It's worked very well for me up till now. It has recently come to light that I may have been doing this wrong the whole time.

I understand that GMS2 has events obviously. Draw create step. Great. Until now I have been doing things like if mouse is clicked then do this under the step code and sometimes In create and draw events.

Now there are other events such as mouse clicks a asynchronous events etc. I have always been under the impression that a step event with a if 'mouse is clicked is then' is the same as a mouse event 'just do it'.

Apparently according to my source 'A programmer but not used GMS' seems to think that this is really important.

It is the difference between an 'interrupt' (I use this term loosely) and lets say a structured loop based approach. I.E do it again and again as many times as you can within one 'cycle'.

This is not an RTFM situation. This is I have read the manual and I'm not sure situation.

The problem I have is that I like to do thing correctly but because of the speed of modern computing makes it difficult to determine if what you are dong Is in fact correct. Because everything is so damn fast you can't easily tell by eyeballing it if it's truly correct or not.

I almost preferred it where everything was slow and short on memory. It makes it hard to learn because your not punished for it. As one should be.

Any advise would be gold. For example what is technically the most efficient way possible (In GMS2) to draw a square in the middle of the screen if a mouse has been clicked screen. (draw event)

This is what I would do:

x1 = 0;
y1 = 0;
x2 = 128;
y2 = 128;

if point_in_rectangle(mouse_x, mouse_y, x1, y1, x2, y2)
{
if mouse_check_button_pressed(const_action_click)
{
draw_rectangle(x1, y1, x2, y2, 1);
}
}

Basically given the very simple code stated above. Is this the best, most effective and efficient way possible to do this in GMS2? Or should I put all mouse events under the mouse event?

Sorry this was a long one I hope this makes sense.

(I'm not a total noob have made several games but my confidence is shaken because I may have been doing it totally ass about face the whole time)
 

GMWolf

aka fel666
Events are not interrupts.
A click event can only happen once per frame.
Events also happen in a strict order (click will happen after step, etc)
Internally, what most likely happens, is GM first dispatches all step events, then all click events (if the mouse was clicked this frame) then the post step event, etc etc.

So it's kinda equivalent.
 
Last edited:
I would love this to be confirmed by another person also because this is what I thought was happening all along. In the sense that the IDE presents an environment which logical to look at and use but when it comes to the nuts and bolts of it we don't know what GMS2 does but assume that it will come good in the end. I hope what you say is true because then I don't have to re think everything.

I presented this argument to the other programmer I mentioned but he was proposing that if game maker did interpret it this way it means your not in control and it's basically can't be 100% sure that what you put in is truly what you will get out.

Thank you I feel a bit better now.
 

Nidoking

Member
I'd just say don't manipulate the same quantities in both your click event and your step event, if it matters in which order they happen during the step when the click is processed. I do things in Begin Step if they have to happen first and End Step if they have to happen last.
 

TheouAegis

Member
Begin Step is run. Then all those fun Input events, alarms, timelines, and whatnot. Then the normal Step Event. Then dome stuff under the hood, such as animation and updating built-in speeds, then Animation End event. Then the End Step Event. Then the Predraw preps everything. Then Begin Draw. Then Draw. Then End Draw. Then...I think GUI events, then finally Postdraw.
 

TsukaYuriko

☄️
Forum Staff
Moderator
I would love this to be confirmed by another person also because this is what I thought was happening all along. In the sense that the IDE presents an environment which logical to look at and use but when it comes to the nuts and bolts of it we don't know what GMS2 does but assume that it will come good in the end.
The manual's event order page literally states that "the exact order that the events are going to occur in each step cannot be clearly stated, simply because it depends on the internal workings of GameMaker Studio 2 and this is subject to change as the software develops", so yes, we in fact don't know what will happen when and are indeed assuming that everything will be okay and happen in the right order unless we take manual control of what executes when. I do this in my own projects by having a central "master mind" object run code for other objects in a pre-determined order exactly because of this reason.

The fragments of known (guaranteed) event order is also listed on the page I linked.

Is this the best, most effective and efficient way possible to do this in GMS2? Or should I put all mouse events under the mouse event?
If you put drawing code in a Mouse event, unless you take manual control of drawing or disable the background of a room entirely, you're not gonna see any of the things you draw. So that wouldn't make a whole lot of sense either way.


That aside, events can exist for two reasons. One of them is functionality, the other is convenience. While they can be both at the same time - for example having End Step guaranteed to run after Step is both convenient and useful - they do not have to, such as the Keyboard events. These are merely for convenience, at least when used in the correct context - if you have configurable controls, they're more of an inconvenience. There's no technical difference between Keyboard events and keyboard_check, aside from when the code is executed (but even the execution order is under your control if you take manual control over it).

When you have no surfaces at all I.E no code blank default screen. Is that the same kind of surface or is it different?
You'd still have the application surface. The only thing that differentiates it from other surfaces is that you can't free it.
 
It seems that we may have a similar philosophy. I tend to skirt around all of the game maker IDE stuff and do things an a much more manual way. I just want to avoid doing things manually when there may be a better way of doing things. For example I could draw a grid using a loop an then find out there is a function for it built it (I haven't found one just an example).

My biggest fear is programming that works well and ill never know it's wrong because it seems to work. Then later you find out why it's wrong and I have already put in a tremendous amount of work that can't be transferred. I'm receiving advise outside of the GMS community. People that are much more skilled than myself but by the same token do not use Gamemaker.

I'm worried about this.
 

GMWolf

aka fel666
My biggest fear is programming that works well and ill never know it's wrong because it seems to work. Then later you find out why it's wrong and I have already put in a tremendous amount of work that can't be transferred. I'm receiving advise outside of the GMS community. People that are much more skilled than myself but by the same token do not use Gamemaker.
The best piece of advice is to make sure you different systems are decoupled.

Make sure you build sensible interfaces and only communicate between systems with those interfaces. That way you can easily change how a system works without needing to rework your entire project.

For instance, you may store a list of enemies somewhere and everything accesses the list directly.
If now you find out a list inst appropriate but you needed some sort of map, or something, you need to go through your entire project fixing things.
If instead you accessed the list through functions (get_enemy_count) (get_nearest_enemy) etc, you can easily change the functions and the rest of your project doesn't need to worry about it.
 

GMWolf

aka fel666
No I mean if you have a list of enemies and all you code is doing ds_list_find_value(global.enemy_list)
If you then change that to a map (for some reason) now you need to change everywhere that code is used.

If instead you wrapped it in functions (get_enemy, etc) now if you change it to a map you only need to change those functions, without looking for everywhere that list was used.
Especially useful in GM as forgetting to change a map/list lookuo somewhere might not give you and error and just do strange things instead

Not just maps and lists but any sort of data store or system.
 
Top