• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] How to make "groups?"

So i'm making a tower defense game, and i got stuck. I'm making the tower, and i don't want to make a variable for every single enemy to check if that enemy's near.

Instead of putting in a variable for every single enemy, could i just do something like:
var en = instance_nearest(x,y,enemygroup);
instead of replacing that enemygroup with every enemy there is in my game on different lines?

Sorry if this is worded badly, thanks for the help!
 

chamaeleon

Member
So i'm making a tower defense game, and i got stuck. I'm making the tower, and i don't want to make a variable for every single enemy to check if that enemy's near.

Instead of putting in a variable for every single enemy, could i just do something like:
var en = instance_nearest(x,y,enemygroup);
instead of replacing that enemygroup with every enemy there is in my game on different lines?

Sorry if this is worded badly, thanks for the help!
The functionality you're looking for is parenting. You can assign an object to be the parent of another object. Then you can use the parent object (which does not need to have an instance in the room) in the function call to get the desired result. If you have different kinds of enemies, implemented by different objects, they can then all be children of a single enemy parent object.
 
Top