2
\$\begingroup\$

Let's say I have an array of objects[i,j], which has been fully populated by objects obj_example. I want to delete the obj_example at position [1,2]. That's simple, as objects[1,2] is currently pointing to that object (or is the object, or whatever logic Gamemaker uses).

But now, the object at objects[1,2] is destroyed.

What if statement would I use to check that makes objects[1,2] return an undefined(or null) value (but, clearly, not make the other, populated objects return such)?

Or how would I otherwise know that the objects[1,2] were destroyed?

EDIT: I added the following to my little project, after object_handler (which was made equal to the objects[i,j] to be deleted) was deleted. It returned "this is defined."

if (is_undefined(object_handler)) 
{
    show_message("this is undefined");
}
else{
    show_message("this is defined");
}

So...is_undefined(n) does not work for this purpose.

\$\endgroup\$
4
  • \$\begingroup\$ What does a destroyed object return currently? Just the object even though it is destroyed? \$\endgroup\$
    – Charanor
    Jul 17, 2017 at 15:27
  • \$\begingroup\$ I am not sure, which is why I'm asking. I'm just running on the assumption that is_undefined(objects[1,2]) works, but I'm hoping to get an answer from someone who actually knows. \$\endgroup\$ Jul 17, 2017 at 15:34
  • \$\begingroup\$ Why don't you test if it works? That seems like a really easy way to find a solution before asking a question. Just print the value of the object before it dies and print the value of the object after. See how the value differs. If the printed value of the dead object is null or undefined or similar you know what to look for. \$\endgroup\$
    – Charanor
    Jul 17, 2017 at 15:38
  • \$\begingroup\$ OK. I tested it, is_undefined(n) does not work. \$\endgroup\$ Jul 17, 2017 at 16:13

1 Answer 1

3
\$\begingroup\$

It seems you have to use instance_exists(object) to check if the object has been deleted or not. This will return false when the object has been deleted. So in your case do

if (!instance_exists(objects[1,2])) {
    //Does not exist
}

To be safe you could also set your variable to a predetermined value when it is destroyed, perhaps set objects[1, 2] to undefined so you know it doesn't exist anymore.

\$\endgroup\$
4
  • \$\begingroup\$ AWESOME! Plugged in instance_exists for is_undefined for my debugging code, and it works as expected. \$\endgroup\$ Jul 17, 2017 at 16:57
  • \$\begingroup\$ Huh...well, game maker must have just patched or something, because, while it worked before, it's now saying that the instance exists, even though I didn't change anything related to the debugging code. It worked just fine 2 days ago! \$\endgroup\$ Jul 20, 2017 at 15:23
  • \$\begingroup\$ @SangoProductions that's probably not the case. You're probably just making a small mistake that's difficult to see at first glance (checking wrong object, not actually completely removing the object, etc). Double-checking your code or stepping through it using a debugger (if game maker offers one of those) should help you find the issue. \$\endgroup\$
    – Charanor
    Jul 20, 2017 at 15:32
  • \$\begingroup\$ I literally changed nothing from last time. It's just acting differently now. \$\endgroup\$ Jul 20, 2017 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .