Can't get a hang of what event to use

M

Mindaugas

Guest
Hello.
Ok so I know the difference between ''create'' and ''step'' events, one is working instantly and other one is looping etc..
Collision event - I know what it's for, but I'm not sure if I need it. How is it different from lets say typing in ''place_meeting (x,y, obj_somegentleman)'' in the step event?
I guess same question goes for draw and some other events. Talking about other events, what's the ''other'' event? it has so many sections, and after seeing in tutorials of how much can be achieved by only using ''create'', ''alarm'' and ''step'' events, I can't really imagine a need of so many events that are built in this program. (obviously I'm wrong)

I know I can read up on each event, and I kind of did but halfway through i got too confused and here I am. Plus I really value a dumbed down opinion from experienced user's point of view.

Thank you!
 
J

Jonathan E. Styles

Guest
It's true that you do not need to use many of the events included in GameMaker: Studio (hereon referred to as: GMS) if you are resourceful enough to use code. You do not even need many of them to generate a complete game! However, this is due to the wonder that is GMS doing most of the heavy lifting for you.

In light of that, due to its nature, YoYo Games wanted to give the user as many possibilities as, er, possible (for lack of a better term) when creating their games without code. Since they wanted to be able to provide users with an all drag-n'-drop experience providing so many different events gives the capability of making intricate games without the use of any code. This broadens the user base of GMS to a much wider variety of customers since more people can easily create games with this wonderful tool.

With the multitude of Events users can determine when and where to draw sprites, if they are affected by viewport settings, and what layer they are being drawn to. We can look for specific keyboard inputs and carryout specific actions when that input is made. Without using a user-written database some of the "Other" Events allow us to keep track of lives and health and we can carryout certain actions based on the end of a sprite animation (typically useful for explosions!).

I can list every Event and go into detail what each is useful for, but you already said you could read-up on that if you were looking for that information. These are simply examples from my own experience as requested. I hope you enjoy your adventures learning the usefulness of all the Events for yourself and enjoy your learning of GMS!
 
A

Azure Spectre

Guest
The others have given some excellent information on the subject, but I'll post some examples anyway. :D

EDIT: Put it all in a spoiler, because it's a bit long...
place_meeting is great if you treat every object the same, and don't need to affect them. The function is frequently used for collisions with solid objects.
Code:
if place_meeting(x+hspd,y,obj_solid)
{
    while(!place_meeting(x+sign(hspd),y,obj_solid))
    {
        x+=sign(hspd);
    }
    hspd=0;
}
or perhaps collisions with stationary hazards
Code:
//step event
if place_meeting(x,y,o_lava) or place_meeting(x,y,o_spikes)
{
    hp-=1;
    invincible_counter=20;
}
Collision events are really nice if you want complex interactions between the two objects involved.
You can use the keyword "other" to refer to the other objects' variables.
Code:
//collision event with obj_bullet
if invincible_counter=0
{
    hp-=other.damage;
    invincible_counter=20;
    with(other)
    {
        instance_destroy();
    }
}
Code:
//collision event with obj_flamejet
if other.active=true and invincible_counter=0
{
    hp-=1;
    invincible_counter=20;
}
The draw event will be one of the more frequently used events after you get used to GM. Every drawing function has to be done in the draw event, or it won't work (with a few exceptions, like with surfaces...).
Code:
//draw_event
draw_set_color(c_blue);
draw_line(x,y,xstart,ystart);
The "other" event you are seeing is just a category of events that don't fit cleanly into the other event types. You will see things like "Room Start", "Animation End", and "Outside Room". They each have their own specific uses of course, but generally speaking, most of them are just events that trigger on certain times, or happen in between the other events, so you can have all of your information where it needs to be before you act on it.
Here's a couple examples of different events, because I realize that's a bit confusing. :confused:
Code:
//Room Start
//Runs after all create events
enemy_count=instance_number(obj_enemy);
enemy_total_hp=0;
with(obj_enemy)
{
    other.enemy_total_hp+=hp;
}
Code:
//end step of obj_camera
//happens after the other step events, so the player has already moved
//center the view on the player
view_xview=obj_player.x-(view_wview[0]/2);
view_yview=obj_player.y-(view_hview[0]/2);
 
Short on time, so I'm not sure if it has been mentioned, but myself, I stick to mainly using just "create", "step", and "draw" events (and their various flavours). The vast majority of other events are worked into my step code, unless I need specific function like "room start/end" or the "async" events, which CAN be simulated by the "step" event, but would either be inconsistent, or just plain inadvisable. The reason why I use as little events as I do is simply because if I'm coding it myself, I know EXACTLY when my code is going to be executed, whereas aside from the main event types, the exact order of events is arbitrary, and is noted by the Devs that it could change without warning between updates. This is also why I don't use alarms and the built in movement systems. Just my two cents!
 
Top