Getting an instance through code?

Discussion in 'Programming' started by bigtunacan, Jan 10, 2019.

  1. bigtunacan

    bigtunacan Member

    Aug 5, 2016
    I was trying to retrieve an instance of an object from another object's event code, but just kept getting an error message.

    pause_id = instance_find(obj_pause_button, noone);
    show_debug_message("Pause ID :: " + pause_id);
    This would continue to error out that pause_id is undefined.

    I ended up working around the issue because this is a single static menu object that I pre-place in the room so I used the instance ID that is shown in the room editor. "inst_5AD07BFE"

    I am still wondering though, what is the proper way to do this dynamically in code as it will probably come up again, but also is it safe/good practice to just use the instance ID shown in the instance layer properties like I have done?
  2. kupo15

    kupo15 Member

    Jun 20, 2016
    The second argument needs to be the number that instance was created. So if you are looking for the first that was created instead of noone it should be 0.

    The second line it should be:

    + string(pause_id))

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