Legacy GM Gamemaker 8.1 object_get_id workaround

Discussion in 'Legacy GameMaker Community Tech Support' started by TheHappyFaceKing, Nov 22, 2019.

  1. TheHappyFaceKing

    TheHappyFaceKing Member

    Joined:
    Jan 6, 2018
    Posts:
    35
    When an object is placed into a room, it seems to get its own id, is there a way to reference the object using that id?

    [​IMG]
     
    Last edited: Nov 22, 2019
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,792
    First, read up on the difference between objects and instances, which applies to all versions of GM. You're trying to get at an instance here, not an object.

    Except for specific contexts such as functions starting with object_*() or the last argument to instance_create(), almost everything else that can take an object ID to talk about something in a room can also take an instance ID to be specific about one out of many instances. Two examples:
    Code:
    (105492).sprite_index
    Code:
    with (105492) instance_destroy();
    None of this is difficult, you just have to stop insisting on object IDs where instance IDs are also accepted and needed for the task at hand.
     
  3. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,139
    Also, the way these IDs work changed in GMS1.x (and again in GMS2). Hardcoding the ID you see in the room editor will cause the project to break if you ever import if (unless you manually change references to the new format). I recommend using Instance Creation Code (right click --> creation code) instead if possible. (Which also changed behavior in Studio, running after the create event instead of before).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice