Gunnar the Clovis
Member
Howdy, I assumed this would be an easy issue / have tons of similar threads on it already, but I can't seem to find any. What I'm trying to do I thought would be very simple, but it's proving to be troubling for me. Hopefully I'm just being stupid and there is an easy solution:
I want to (easily) pass an object_index into a function, instead of a single instance of that object type.
Essentially, I would like to use functions as proxies for the with() statement, where I can pass in either a single instance derived from a given object type or operate on many instances from that object type. In other words, I want to delay when the object type is evaluated by the with() statement via a function. That's still a bit confusing to word, so here's my code:
I was writing this a lot:
But with different object types (instead of obj_my_type), plus setting those two variables to false instead of true half the time. Seems like the perfect place to write a function, right?
Seems good. This cuts down my code significantly, makes almost the entire project more readable and way shorter in length. It's crazy how much that added up.
However, now it doesn't work unless there's a single instance of the given object type, only operating on the first
Adding a
This was false.
I'd ideally like to be able to call show_hide_object() with a given object_index even if there are 1 or 200 instances of that object type.
However, I'd be happy enough if I had to make a near duplicate version of show_hide_object() that's just for when there are many instances of a given object type instead of guaranteed just one.
Do you have any solutions to this? Am I just being stupid?
I appreciate your time and help, thanks le million!
I want to (easily) pass an object_index into a function, instead of a single instance of that object type.
Essentially, I would like to use functions as proxies for the with() statement, where I can pass in either a single instance derived from a given object type or operate on many instances from that object type. In other words, I want to delay when the object type is evaluated by the with() statement via a function. That's still a bit confusing to word, so here's my code:
I was writing this a lot:
GML:
with(obj_my_type)
{
drawingActive = true;
drawingActive = true;
image_blend = c_white;
}
GML:
/// @function show_hide_object(_obj, _show)
/// @param {id} _obj The object to show or hide with default blend
/// @param {bool} _show Whether to show the object or hide the object
function show_hide_object(_obj, _show)
{
with(_obj)
{
drawingActive = _show;
logicActive = _show;
image_blend = c_white;
}
}
GML:
// Hide and disable GUI buttons
show_hide_object(obj_gui_button_clear, false);
show_hide_object(obj_gui_button_deal, false);
_obj
it finds. Of course, makes sense, I expected that. And 95% of the time there is guaranteed to only be one instance of that object type. But sometimes I need to hide or show an entire object type at once, but I figured that would simple as the following:
GML:
// Hide and disable GUI buttons
show_hide_object(obj_gui_button_clear, false);
show_hide_object(obj_gui_button_deal, false);
show_hide_object(obj_chip.object_index, false); // Hide chip dock
.object_index
into the argument when called I thought would do the trick, passing the object_index object type itself instead of the instance id of the first instance of that object type found, so then in the show_hide_object() function the with() statement would run the code on all instances of that object type.This was false.
obj_my_type.object_index
seems to evaluate into the exact same thing as obj_my_type
, namely the instance id of the first instance of that object type found. I guess that makes sense... but that's rather disappointing and annoying. I've been looking around for some function or something to alleviate this problem, letting me pass an object_index itself into my above show_hide_object() function even if the calling line itself is more annoying, but I've come up empty.I'd ideally like to be able to call show_hide_object() with a given object_index even if there are 1 or 200 instances of that object type.
However, I'd be happy enough if I had to make a near duplicate version of show_hide_object() that's just for when there are many instances of a given object type instead of guaranteed just one.
Do you have any solutions to this? Am I just being stupid?
I appreciate your time and help, thanks le million!