r/gamemaker•
Gompomp

Instance variable not recognized by a different instance

Resolved

I have two objects, let's say 'define' and 'setup'. Both 'define' and 'setup' are in the room and 'define' comes first.

In obj 'define' I declare this instance variable copper = 1;

In obj 'setup' I try and add the copper to a ds list.

global.deck = ds_list_create();
ds_list_add(global.deck, obj_define.copper);

I get this error when i try to run the program

Variable obj_define.<unknown variable>(100400, -2147483648) not set before reading it.
at gml_Object_obj_setup_Create_0 (line 27) - ds_list_add(global.deck,
obj_define.copper);

Posted Sep 17, 2020, 6:39 AM UTC

15
Westwud•

This works for me. Did you try to recreate it in an empty poject? The only thing that I can think of is if you have defined copper as a local variable:

var copper = 1;

instead of:

copper = 1;
1
GompompOP•

Its like the second example you gave. It does work in an empty project, but in my current project I disabled all the objects except these two and that didn't fix it.

1
Westwud•

Can't say for sure what's going on, try recreating the room, starting from those 2 objects only.

1
FaultyFunctions@FaultyFunctions•

Try to access copper in the step event of the second object. If it works, then check your instance creation order in the room. If it doesn't work, then I have no idea what's going on.

1
GompompOP•

Issue was instance creation order was wrong. I thought that the order in the instance layer was the creation order, but it turns out the creation order is different and in the room settings.

2