• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Getting an instance through code?

B

bigtunacan

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

Code:
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?
 

kupo15

Member
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))
 
Top