Object IDs stored in ds_list result in <invalid instance>

Q

qxface

Guest
EDIT: With a little more digging, it looks like this only happens when I change rooms after creating the ds_list. Is there a way to mark a ds_list as persistent?


EDIT2: Duh! The objects IN the ds_list weren't persistent, so they were getting destroyed when the room changed. The ds_list still held the value of the object IDs, but they no longer referred to existing objects.

GM 1.4.1804

I create some objects and store their IDs in a ds_list. I can immediately turn around and use the accessor to get the object ID and see all the object's variables.

However, if another object later uses the ds_list's accessor, it gets the object's ID just fine, but attempting to read its variables gives the error: "Unable to find any instance for object index '100005' name '<undefined>'" In debug mode, I can get the correct object ID by using the accessor, but if i tell the debugger that the ID number is an Instance instead of a Real, I get an error saying "<invalid instance>".

In my main o_game object, I create an object, insert it into the ds_list, and then print some debug statements:

var cID = instance_create(50, 50, o_thief);
ds_list_add(global.charList, cID);
show_debug_message("o_game.endStep thief: " + string(global.charList[| 0]));
show_debug_message("o_game.endStep thiefID x : " + string(cID.x));
show_debug_message("o_game.endStep thiefListID x : " + string(global.charList[| 0].x));​

Output is:
o_game.endStep thief: 100005
o_game.endStep thiefID x : 50
o_game.endStep thiefListID x : 50

But, if I do the same thing from a different object:

var cID = global.charList[| 0];
show_debug_message("o_pointer.endStep char0: " + string(global.charList[| 0]));
show_debug_message("o_pointer.endStep char0: " + string(cID));
show_debug_message("o_pointer.endStep char0ID x : " + string(cID.x));
show_debug_message("o_pointer.endStep char0ListID x : " + string(global.charList[| 0].x));​

The output is:
o_pointer.endStep char0: 100005
o_pointer.endStep char0: 100005
and then an error saying:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event2
for object o_pointer:

Unable to find any instance for object index '100005' name '<undefined>'
at (line 15) - show_debug_message("o_pointer.endStep char0ID x : " + string(cID.x));
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_o_pointer_StepEndEvent_1 (line 15)​

What I don't understand is that it finds and returns the correct object ID (in this case 100005), but it doesn't seem to treat that number as an object instance and can't see the x value of the object.

I feel like I need to "cast" 100005 as an object to get GM to realize that it should treat the number as an ID instead of a number, but I'm not sure if that's a real thing in GM. I'm missing some basic fact about how a ds_list handles accessing object IDs.

Thanks for any help on this!
 
Last edited by a moderator:

Simon Gust

Member
As you suspected, the ids of instances are lost on room change.
What you must do is save the instances by storing the object_indexes, positions and what have you and recreate them using instance_create() and assigning the data back from the list.
 
Top