SOLVED How to compare return of the parent_get function

Petrik33

Member
Hello everybody, probably the heading for this thread sounds strange but I Really have troubles when dealing with function object_get_parent and object_index variable, so what I want to achieve is simply make one object perform the action depending on what it collided with, so For Example, if the enemy object collides with player object it will decrease the hp of player. So to realize it I have parent object for player, called pobj_hero, so the player is instance of object called obj_hero_druid which parent is pobj_hero. Next, I have Collision Checking script that returns the instance_id of the object you collide with, and lastly I have step event for enemy object:
GML:
#region//Movement

var collided_with = EntityMovement();//Script returns instance_id
if(object_get_parent(collided_with)=pobj_hero.object_index)//Having just pobj_hero
//Doesn't work too
{
// *** Stop Point for Debugging
    with(collided_with)
    {
        movement_direction = 0;
        state = state_pushed;
        pushed_speed = other.pushing_speed;
        pushed_direction = radtodeg(arccos(cos(degtorad(other.pushing_direction) * other.movement_direction )))
        Vx = lengthdir_x(pushed_speed,pushed_direction);;
        Vy = lengthdir_y(pushed_speed,pushed_direction);;
        x += Vx
        y += Vy
        RecieveDamage(1);
    }
}
So, the problem is in the first 2 lines of the code, I discovered it by using debug mode, and it didn't stop on the stop point(marked in code) inside "if" statement.
Also having just pobj_hero instead of pobj_hero.object_index doesn't work too. So I am really stunned, why doesn't it work if the Manual seems to say that object_get_parent returns unique object_index?
Still it could be my fault somewhere else but I just want to know how to realize such things properly and how this stuff rowks because it ain't the first time I am having problems here with. Help please.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Well doing "pobj_hero.object_index " is the same as doing "object_index.object_index" so you were correct to use the original "pobj_hero" on it's own. That said, you DO need to use the "." method if you are using an instance, which may be the issue you are having... so try:

if object_get_parent(collided_with.object_index)
 

FrostyCat

Redemption Seeker
The Manual entry for object_get_parent() says that it takes an object ID as its argument, you passed it an instance ID. Do this instead:
GML:
if (object_get_parent(collided_with.object_index) == pobj_hero)
Or if you will be inheriting more than one level down:
GML:
if (object_is_ancestor(collided_with.object_index, pobj_hero))
You have the exact same misconception as the one on this topic I've responded to before. I suggest you read my explanation there as well.
 

Petrik33

Member
The Manual entry for object_get_parent() says that it takes an object ID as its argument, you passed it an instance ID. Do this instead:
GML:
if (object_get_parent(collided_with.object_index) == pobj_hero)
Or if you will be inheriting more than one level down:
GML:
if (object_is_ancestor(collided_with.object_index, pobj_hero))
You have the exact same misconception as the one on this topic I've responded to before. I suggest you read my explanation there as well.
I am very sorry, I have found it myself just a little time after I posted the thread(this always happens:) ) but then I forgot deleting thsi thread diving back in the code instead, but still thank you!
 

Petrik33

Member
Well doing "pobj_hero.object_index " is the same as doing "object_index.object_index" so you were correct to use the original "pobj_hero" on it's own. That said, you DO need to use the "." method if you are using an instance, which may be the issue you are having... so try:

if object_get_parent(collided_with.object_index)
Thank you too!
 
Top