with() and optimization?

Neptune

Member
Is there a way to "deactivate" a single instance so that it is not running and not even recognized in a with(object_index) pass?
Currently, I can only think to make a lightweight place holder object in its place... Or some other entity to store the bare minimum of info about it for when it's time to become active again.

Any information is appreciated!
 

Neptune

Member
Hmmm thanks for reply. That seems more for mass activation/deactivation, and if I recall is really taxing to quickly hop back and forth. I may have to wing it...
 

Tornado

Member
Maybe you could put a flag into Create Event of your object like:
isActive = true;

and just set it to false for your needed instance.

then in "with" you can do this:
Code:
with (objSomething)
{
    if (isActive) {
       // do whatever you want to do here
    }
}
There is also instance_change(...) method, but I wouldn't recommend it if it is not neccessary.
 
Last edited:

TheouAegis

Member
Hmmm thanks for reply. That seems more for mass activation/deactivation, and if I recall is really taxing to quickly hop back and forth. I may have to wing it...
Then don't hop back and forth. And all the deactivate functions can be used on a single instance as needed.

Using the variable method will function nearly identical to deactivating an instance, albeit a tad slower. GM will already check if the instance is active, now you're checking twice if it's active. Furthermore, the isActive method will not prevent that instance from being processed in every event, which is why once you deactivate a bunch of instances the fps jumps up drastically. Additionally, since the events are still processed with the isActive method, the Draw Event will still run. If you want your instance deactivated but still drawn, the variable method is probably the best option. If speed is a serious consideration, then deactivating the instances and storing their id in an array or list and then having your controller object loop through the array/list to manually draw each instance in the list would probably be fast enough.
 
Z

zendraw

Guest
arent the instances alredy in a list/array of sorts? i mean WITH () is a loop that loops thru all instances of an object.
can we activate a specific instance by using its ID? instance_Activate_object(myItem); ?
 

chamaeleon

Member
The manual is fairly clear on the matter
With this function you can deactivate a single instance or all instances of a specific object [...]
objThe object or instance to deactivate (the keyword all can also be used).
If only one instance of interest for deactivation, just pass it instead of an object.
 

Neptune

Member
Interesting, alright. Well in my case, through parenting, it's fairly easy to inherit a if a && b && c {exit} kind of thing in the step & draw. I suppose if the instance count starts to bog things down I'll mess with the function more.
 
Top