• 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!

Variable references invalid object (-4).<unknown variable>

obscene

Member
Maybe I've lost my mind, but this looks pretty cut and dry to me.

This line:
with (obj_mother_tentacle_short_ceiling) instance_destroy();

Suddenly Returns this error:
Pop :: Execution Error - Variable references invalid object (-4).<unknown variable>
at gml_Object_obj_mother_StepNormalEvent_2 (line 97) - with (obj_mother_tentacle_short_ceiling) instance_destroy();

The object exists. An instance of the object exists. I'm not trying to reference any variable of it. So how does that error make any sense?
 

samspade

Member
I also do not see an error.

What happens if you put brackets around it (instead of relying on GML's standard interpretation) or try instance_destroy(obj_mother_tentacle_short_ceiling)?

I don't know why this would matter, but the default of instance_destroy is to run the destroy event of the objecting being destroyed. Is there anything in the destroy event of short ceiling that could cause a problem (that doesn't seem to be what the error message is saying). What if you tried instance_destroy(id, false)?

Other questions.
  • How many instances of that object are there?
  • What does the debugger say about the existence of the instance?
  • Any inheritance issues to consider?
 

Slyddar

Member
What happens if you test first?
Code:
if instance_exists(obj_mother_tentacle_short_ceiling)
{
  with (obj_mother_tentacle_short_ceiling) instance_destroy();
}
 

obscene

Member
Yeah, can't find anywhere where I accidentally declared it as a variable. Tried this...

Changed to:
Code:
if (instance_exists(obj_mother_tentacle_short_ceiling))
    {
    with (obj_mother_tentacle_short_ceiling) instance_destroy();
    }
Now the error pops up when checking if the instance exists:
Pop :: Execution Error - Variable references invalid object (-4).<unknown variable>
at gml_Object_obj_mother_StepNormalEvent_2 (line 97) - if (instance_exists(obj_mother_tentacle_short_ceiling))

Going through all related code and adding parentheses, brackets, semicolons, etc that may be missing...
 
Last edited:

obscene

Member
OK, so problem solved. Not sure what it was, but I went through all the code above this and made sure all my with's, if's, etc had parenthesis and found a couple of missing semicolons. Fixed. Thanks for the help guys!
 

Carloskhard

Member
OK, so problem solved. Not sure what it was, but I went through all the code above this and made sure all my with's, if's, etc had parenthesis and found a couple of missing semicolons. Fixed. Thanks for the help guys!
Hey, do you remember what semicolons were you missing?
I'm having the same problem and I've been the whole day trying to understand why is failing.
I use this code:
Code:
with (colliding){
    show_debug_message(colliding)
    instance_destroy(colliding);
}
and in the debug I can see the ID of the object is correct,but on the error message it shows this:
Code:
Pop :: Execution Error - Variable references invalid object (-4).<unknown variable>
why is saying the object was "-4" if clearly the objects was something like "100045"?
I need help
 

obscene

Member
I can't remember exactly as it's been awhile, but seems like I just went and checked all the code that preceded this part and just found that some random semicolons were missing on other lines and things like that. Somehow some sloppy syntax snowballed into a weird bug later on.

I would just start scrolling up and looking for anything that's not 100% kosher.
 
Top