child with multiple parents (grouping objects)

mX273

Member
Hi guys

I just figured out, that a child object can have just one parent. I would like to group some objects for different collision checks and behaviours, but some objects has to be in multiple groups.
How can i solve this?

Example (Pseudo code):
//--------------------------------------------------------------------------------------------------------------------------
GML:
// Enemy1 is in group " obj_parent_deadlyObject" and in the group " obj_parent_giveItemWhenDestroyed"
// Enemy2 is in group " obj_parent_deadlyObject"
// Enemy3 is in group " obj_parent_deadlyObject" and in the group  "obj_parent_glowingObject"

// obj_player
if (place_meeting(x, y, obj_parent_deadlyObject)
{
    //.... checks collision for deadly objects
    //  Player dies
}

with (obj_parent_glowingObject)
{
    gpu_set_blendmode(bm_add)
    draw_self()
    gpu_set_blendmode(bm_normal)
}
 

Mk.2

Member
GML:
// Enemy1 is in group " obj_parent_giveItemWhenDestroyed"
// Enemy2 is in group " obj_parent_deadlyObject"
// Enemy3 is in group " obj_parent_glowingObject"

// obj_parent_giveItemWhenDestroyed is in group " obj_parent_deadlyObject"
// obj_parent_glowingObject is in group " obj_parent_deadlyObject"
 

NightFrost

Member
All you can do is define child and grandhild groups with increasing specifity. If you try to address multiple behaviors through object parenting, it will inevitably lead to clashes. If you think of your groups as circles, you can only add them inside or outside other circles. There can be no partial overlap in their borders. If this doesn't work by wrangling around your grandparent and grandchild relations, you'll have to formulate another approach.
 

Nidoking

Member
GML 2.3 will have Tags that can do things like this. You can't use a Tag in a with, as far as I know (I only just got 2.3, and some of the known bugs are getting in the way of porting my game to it), but you can check whether an instance's object has a particular Tag and base logic on that.
 

NightFrost

Member
GML 2.3 will have Tags that can do things like this. You can't use a Tag in a with, as far as I know (I only just got 2.3, and some of the known bugs are getting in the way of porting my game to it), but you can check whether an instance's object has a particular Tag and base logic on that.
Sounds like enumerator-based types I am using in a project. Although I do have an object parent tree... obj_world_parent is for collision master checks, and has the children obj_invisible_block, obj_decoration and obj_interactive, the last of which has children obj_npc and obj_item. These two would have children like obj_guard, obj_magic_circle and obj_table. However, since I need to collide with guard and table, but walk across magic circle, they also bear enum types that are checked to exclude one from collisions. TBH, as the code has evolved to the point where enum types are always checked everywhere, I could tear out the parents tree as it now serves no purpose except make certain with(foo) and collision checks target a narrower number of instances in the room.
 

woods

Member
hmm... a set of variables in each enemy object?

is_deadly = true
is_glowing = true

then have a script for is_glowing

...just a thought
 
Top