Event after certain amount of killed enemies

P

PopatoChisp

Guest
Hello,
I'm pretty new to Game Maker, and programming in generall, and I wanted to ask if its possible to make an event happen after a certain number of enemies was killed (in an Rpg game for example)
For example when you kill 10 enemies, a door opens, or another person joins your party but if you don't kill the 10 enemies, this event doesn't happen.

I saw some things about flags (i think that's what they are called), that get activated if the player does a certain thing, and when a certain number of flags is activated an event occurs, but I'm not sure.

(Also, first post on this forum, so hello to everybody :) )
 
A

Aura

Guest
Yes, you can use flags. For instance, if you want to open the door when 10 enemies have been killed, you'll do something like this:

Create:
Code:
event_done = false;
door_open = false;
Step:
Code:
if (global.killed_enemies >= 10) {
   if (!event_done) {
      door_open = true;
      event_done = true;
   }
}
...where event_done has been used (although completely unneccesary in this case) to show how flags can be used to make sure that an event/action is performed only once.

Another suggestion: Use the concerned object (door object in this case) to handle events or actions related to the same instead of using a single object for everything. It would makes things easier to handle.
 
P

PopatoChisp

Guest
Yes, you can use flags. For instance, if you want to open the door when 10 enemies have been killed, you'll do something like this:

Create:
Code:
event_done = false;
door_open = false;
Step:
Code:
if (global.killed_enemies >= 10) {
   if (!event_done) {
      door_open = true;
      event_done = true;
   }
}
...where event_done has been used (although completely unneccesary in this case) to show how flags can be used to make sure that an event/action is performed only once.

Another suggestion: Use the concerned object (door object in this case) to handle events or actions related to the same instead of using a single object for everything. It would makes things easier to handle.
Thank you :)
Can I also use flags if I want to do sometihng bigger then opening a door? For example a different game-route (like multiple ending games have them sometimes)
or should I use something else for this kind of thing?
 

Genetix

Member
Absolutely - so what Aura is suggesting is to use a Global Variable (Good to get familiar and comfortable with these!) to keep track of how many enemies have been killed. Everytime an enemy is killed, increment that variable - then for each Door object, or whatever you use to control the game route and ending, you can reference that global variable.

for example:
if global.enemies_killed > 100 {special ending A} else {special ending B}
 

Yal

šŸ§ *penguin noises*
GMC Elder
Yeah, you can use flags and counters for more or less anything... the only thing to keep in mind is to check them at the right point. If you want something to happen the very moment you fulfill the condition, you'd check in the Step event (e.g. if you need to kill enough enemies in the same room); if you can't fulfill a change in the room it is in, like a door in a different map opening, or choosing between two cutscenes, it's enough to use the Create or Room Start event.
 
Top