Gah! I've been bitten by scope haha thanks Ome6a. I have a function that gets called by set_click_func so yeah.. that's it! I'll use the id instead :)
Viewing post in Switching from one window to another cleanly?
I've found scope to be very difficult to figure out in GML when using script_execute, to be honest. For instance, what you did will work fine for windows/macos export, but if you export to HTML5, it will sometimes throw an error that it is unable to find your element.
It's generally just best practice to pass in all objects you use or reference for safety:
my_button = auto_button(/* data */);
my_button.set_click_func(function(_obj, _btn) {
_btn.color = c_white; // eg.
_obj.variable = 2; // eg.
}, [self, my_button]);Awesome!
My set click now looks like this:
options[0].set_click_func(function(objid) { edit(objid); }, [self]);And that's passing in the object so I can use instance_destroy to close it right in the function. Perfect!
Just incase you're wondering, I'm using a function in the function so I can call the same code for both controller and mouse. My controller code calls the function from Step, so I didn't want to duplicate that code in set_click_func as well as there.
Anyhoo - thanks again for your help I really appreciate it :)