samspade
Member
I'm still working through the various new features of 2.3 and I've come across another question:
Not only does the above code not error out, it will print 110 to the output line despite the fact object 1 is destroyed (which can be verified in the debugger and through other methods such as trying to reference the instance id).
How, or perhaps why, does this work? The why sort of makes sense, as the function is bound to an instance of object 1 and the reference to that function hasn't been lost because it is stored in a global variable, but on the other hand the instance is destroyed and the variable, my_variable presumably is as well, except that it isn't and can still be referenced through the use of this function.
GML:
///object 1 create event
my_variable = 100;
global.global_func = function() {
my_variable += 10;
show_debug_message(my_variable);
show_debug_message("Hello?");
}
instance_destroy();
GML:
///object 2 some event that fires after object 1's create event
global.global_func();
How, or perhaps why, does this work? The why sort of makes sense, as the function is bound to an instance of object 1 and the reference to that function hasn't been lost because it is stored in a global variable, but on the other hand the instance is destroyed and the variable, my_variable presumably is as well, except that it isn't and can still be referenced through the use of this function.