1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Check if id of instances is a certain object

Discussion in 'Programming' started by Simulacron, Jul 19, 2017.

  1. Simulacron

    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?
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,846
    target.object_index != oInputable
     
  3. Wayfarer

    Wayfarer Member

    Joined:
    Jan 3, 2017
    Posts:
    191
    Thinking about this... I think you might actually need to check the parent:
    Code:
    if (object_get_parent(target.object_index) != oInputable) {
    }
    
     
    Last edited: Jul 19, 2017
  4. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,846
    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.
     
    Wayfarer likes this.
  5. Wayfarer

    Wayfarer Member

    Joined:
    Jan 3, 2017
    Posts:
    191
    @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)

    That sounds like a better idea.
     
    Last edited: Jul 19, 2017

Share This Page