GameMaker Object/Instance Tags

So, I think I already know the answer to my question, but I don't like it very much, so I'm asking here to see if anyone has any better ideas.

I need a way to separate objects into useful categories, so I can treat them correctly in collision events mostly, but it's useful for a lot of things. Right now, I'm using a lot of parent and child objects. For example, I have obj_type_wall which is the parent for all "solid" objects that the player and enemies cannot walk through.

This works okay, but now that my project has gotten fairly complex, this method is growing to be kind of annoying. Here's an example of where simple parenting trees do not work at all. I have two types of enemies, flying enemies and ground enemies. They behave exactly the same, except that the ground enemies behave like walls and will not cross the path of other wall type instances, while the flying enemies can go wherever they want. If I want to group them both under a parent called obj_type_enemy so that I can easily address both of them when I'm working with the player weapons, I have a dilemma. Either both of them will also have to be children of obj_type_wall too, or neither of them can be. Which means no matter what I do I am required to have extra checks in like, 2 or 3 different places.

I would like to find a way instead to reference objects by a tag, like in MC or something. "With a collision with all instances with the tag: "wall", stop moving". Or "target is equal to the nearest instance with the tag of "enemy" and the tag of "flying"".

There does not seem to be any way to check if a particular variable exists, which basically means I have to define a variable as either true or false for every single object in the entire project (which is like, 80). I could simplify it a little bit with a generic array or something with a list of tags but... it feels really stupid to define 10 variables for something when I only need to do checks like this occasionally. And like, if I forget one... It's just a hassle.

Sorry for the rant, is there any better solutions? I'm pretty sure the answer is no but... I want to check before completely revamping my project for the third time.
 
J

JFitch

Guest
You could use event_perform_object. That's a way of allowing an object to have multiple parents, or different parents for different events.
 
M

Mr. Marx

Guest
Bumping an old post, but why don't you just make a similar parenting tree:
Code:
oEntities: {
    oPlayer;
    oMobs: {
        oAirMobs: {
            oBat;
            oDragon;
            oReaper;
            ...
        }
        oGroundMobs: {
            oUndead;
            oWolf;
            ...
        }
    }
}
Just simple things... parent of a parent is a parent for a child. #Parentception lol
 
That works fine. But I already know how to do that, I don't think you understood my question:

What if I want oBat and oWolf to also be considered creatures that can be tamed?

I can't give those two a parent without also parenting the others in the group.

For that example it can just be an exception coded into those two objects, but once I get 40 enemies, and 20 of them are tamable, I don't really want to mess with that.

At any rate, for my current project I have worked it out with a combination of separate lists to check for certain types of things and built in variables I can change to true or false.
 
A

arirish

Guest
Use a 2D array. Pop it into a script you can call whenever you need to pull a piece of information.
Code:
bestiary[0,0]="Bat";
bestiary[0,1]=1 //flying
bestiary[0,2]=1 //tameable

bestiary[1,0]="Wolf";
bestiary[1,1]=0 //ground
bestiary[1,2]=1 //tameable

bestiary[2,0]="Horrible Sludge Monster";
bestiary[2,1]=0; //ground
bestiary[2,2]=0; //untameable
I use something like this to hold everything from enemy HP, attack and defence, speed, to movement patterns, gold drops, etc.
 
Top