Check if id of instances is a certain object

S

Simulacron

Guest
I want to check if my oPlayer instance can see another instance (oInputable), without beeing blocked by all other instances, grouped under the object oNotInputable. Both of these objects are children of the oSolid object that makes them all solid for the Player.
To check this collision I use the following code:
Code:
target = noone; //Resets target
target = collision_line_first(oPlayer.x+global.size/2,oPlayer.y+global.size/2,mouse_x,mouse_y,oSolid,false,false); //finds first solide object thats between the mouse and the player (global.size is just a variable to make it easier to change the scale of the game and centers the collision line in the middle of the player)
if target != oInputable{ //Check if instance id is equal object --> doesn't work
    target = noone; //reset target if instances isn't an oInputable
}
collision_line_first is a script that returns the first object that the collision line hits.
After I got the instance id with this script I want to check if I got my oInputable instance or an instance from the oNotInputable group. I tried to check if the instance is equal to the oInputable, but I think that this isn't possible. Is there any other way to check which object type the instance is?
 

jo-thijs

Member
I want to check if my oPlayer instance can see another instance (oInputable), without beeing blocked by all other instances, grouped under the object oNotInputable. Both of these objects are children of the oSolid object that makes them all solid for the Player.
To check this collision I use the following code:
Code:
target = noone; //Resets target
target = collision_line_first(oPlayer.x+global.size/2,oPlayer.y+global.size/2,mouse_x,mouse_y,oSolid,false,false); //finds first solide object thats between the mouse and the player (global.size is just a variable to make it easier to change the scale of the game and centers the collision line in the middle of the player)
if target != oInputable{ //Check if instance id is equal object --> doesn't work
    target = noone; //reset target if instances isn't an oInputable
}
collision_line_first is a script that returns the first object that the collision line hits.
After I got the instance id with this script I want to check if I got my oInputable instance or an instance from the oNotInputable group. I tried to check if the instance is equal to the oInputable, but I think that this isn't possible. Is there any other way to check which object type the instance is?
target.object_index != oInputable
 
W

Wayfarer

Guest
Thinking about this... I think you might actually need to check the parent:
Code:
if (object_get_parent(target.object_index) != oInputable) {
}
 
Last edited:

jo-thijs

Member
Thinking about this... I think you might actually need to check the parent:
Code:
if (object_get_parent(target) != oInputable.object_index) {
}
Using oInputable without object_index is safer, as you don't assume there's an active instance of oInputable in the room that way
object_get_parent expects an object id, but you provide it an instance id, so it will probably not work
Using object_is_ancestor(oInputable, target.object_index) would be even safer.
 
W

Wayfarer

Guest
@jo-thijs: Was just about to edit the ".object_index" out (and have now :p). Actually, yeah, that's true about expecting an object index. I did something similar to this the other day and I thought what I did above worked. I'll check now.

Edit:
I've fixed the code now so it works. Just had to add ".object_index" after the target (funnily enough :D)

jo-thijs said:
Using object_is_ancestor(oInputable, target.object_index) would be even safer.
That sounds like a better idea.
 
Last edited:
Top