GameMaker comparing ID`s

Z

zendraw

Guest
essentially what i want to do is
if (owner.id==other.owner.id) {};

but in case the instace has no owner, it will throw an error, so can i ask instead
if (owner==other.owner) {};

this way if owner doesnt exist atleast it wont throw an error.

will the both IF`s work the same way, or atleast give the same resault?
 

GMWolf

aka fel666
Unless 2.3 changed things dramatically, doing owner == other.owner should work just fine.
It may be different if you use structs. Idk if structs compare by address or by value.

But (at least pre 2.3) when you store an instance you are really storing it's id. So doing owner.id and just owner is equivalent.

Actually idk if it will let you but I suppose you could chain as many .IDs as you like.
Owner.id.id.id.id.id...
 
Z

zendraw

Guest
if ( owner != noone )
{

}

Apologies if this is not what you need.
the point is to compare if 2 instances have the same OWNER, and we are trying to do that comparison without entering the OWNER, becouse there is a case in which one of the instances may not have an OWNER.
 

GMWolf

aka fel666
the point is to compare if 2 instances have the same OWNER, and we are trying to do that comparison without entering the OWNER, becouse there is a case in which one of the instances may not have an OWNER.
I think what they meant was to first check if the owner was none before trying to compare the IDs.
 

FrostyCat

Redemption Seeker
Then owner != other.owner is perfectly fine. The only instances you're physically entering in that expression is the current and "other" instance.

Now, if the issue is that the "other" instance doesn't have an instance variable named owner, that is an architectural problem in other places of your code. If it's a collision event, that object should have owner initialized to noone for not having an owner. Don't just skip the initialization, and don't hope the runner would magically forgive the absence of the variable. If it's a with statement, same deal --- don't start it from or target anything that wouldn't have an instance variable named owner.
 
Z

zendraw

Guest
there is a situation in which the instance will not have an owner, and afaik if you set an instance`s ID to a variable, and then that instance is destroyed, the variable becomes -4. and whenever i have such variables that will hold instances, i aways set them to -4.
 

TsukaYuriko

☄️
Forum Staff
Moderator
afaik if you set an instance`s ID to a variable, and then that instance is destroyed, the variable becomes -4.
That is incorrect. The variable remains unchanged, still containing the ID of a now non-existant instance.
 

FrostyCat

Redemption Seeker
afaik if you set an instance`s ID to a variable, and then that instance is destroyed, the variable becomes -4.
Let's say there is a Yellow Pages phone book in an attic. Do the phone numbers in it magically empty off the pages as their respective owners move out of town or die?

If you understand what the common-sense answer for that is, you should also understand why your statement is contrary to common sense.

GML is a language exquisitely dependent on ID-based addressing, in which hardly anyone knows anything about ID-based addressing.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Currently, it starts at 100000 and increments by 1 for every new instance. This is undocumented, however, so don't rely on it.

A lack of an instance can be accurately and unmistakably represented by noone.
 
Z

zendraw

Guest
Currently, it starts at 100000 and increments by 1 for every new instance. This is undocumented, however, so don't rely on it.

A lack of an instance can be accurately and unmistakably represented by noone.
so if the instance that the OWNER variable holds, dies, OWNER becomes NOONE automatically, or OWNER remains that same value it was? if its the second and lets say the situation is, all instances of that type are dead, if we create a new instance of that type, wont its ID be 100000? so if OWNER keeps the value of the instance it was, it will automatically hold the ID of the newly created instance.
 

FrostyCat

Redemption Seeker
so if the instance that the OWNER variable holds, dies, OWNER becomes NOONE automatically, or OWNER remains that same value it was?
Your owner variable is NOT holding the instance, it is holding a numeric ID of the instance. Therefore, when that instance is gone, owner will NOT automatically receive any new value. TsukaYuriko has told you this and so have I.

It is like if a person dies, his/her phone number would still be on any phone book that has it on record. But if you find that number on an old phone book and cold-call it, you'll know that person is no longer there.
if its the second and lets say the situation is, all instances of that type are dead, if we create a new instance of that type, wont its ID be 100000? so if OWNER keeps the value of the instance it was, it will automatically hold the ID of the newly created instance.
Instance IDs are not reused, so both statements are false.

Stop expecting automatic treatment in this matter, and your code will go in the right direction.
 
Z

zendraw

Guest
Your owner variable is NOT holding the instance, it is holding a numeric ID of the instance. Therefore, when that instance is gone, owner will NOT automatically receive any new value. TsukaYuriko has told you this and so have I.

It is like if a person dies, his/her phone number would still be on any phone book that has it on record. But if you find that number on an old phone book and cold-call it, you'll know that person is no longer there.

Instance IDs are not reused, so both statements are false.

Stop expecting automatic treatment in this matter, and your code will go in the right direction.
these things are not answered in the manual, im agathering knowledge here, dont assume lazyness. knowing how things work on all floors lets you be smart with the code, you may think it as lazyness, it is not. and these details are important. that ID`s are not reused, which brings the next question, when the IDs reach the limit of values then what happens? do they start over at 100000 or somthing somthing happens? what if i still have my OWNER variable that holds the ID of the 1st instance, if the ID value warps back at 100000 well hold its value automatically.

speaking of automation, every programmer pursues automation in coding...
 

samspade

Member
and these details are important. that ID`s are not reused, which brings the next question, when the IDs reach the limit of values then what happens? do they start over at 100000 or somthing somthing happens?
As @TsukaYuriko said, the way GM tracks instance ids is subject to change at any time and without warning. So although you could figure out the answer to this question if you wanted, the answer would only be interesting, not useful as you couldn't rely on it. There's no guarantee that it would work consistently across platforms or updates.

what if i still have my OWNER variable that holds the ID of the 1st instance, if the ID value warps back at 100000 well hold its value automatically.
The variably would hold the same number. As pointed out before an instance id is just a number. So if instances were later renumbered or instance ids were removed that number would point to a different instance or nowhere. This is why, for example, you can't save out instance ids and then load them back in and expect it to work. Because there's no guarantee that anything will match up.
 

TsukaYuriko

☄️
Forum Staff
Moderator
when the IDs reach the limit of values then what happens?
This is undocumented.

You can test it yourself by creating a couple hundred million instances and see what happens once their IDs reach the limit, wherever that is.
 
Z

zendraw

Guest
the rules are bound to the IDE and runtime versions right? and if i dont update but finish a project in a specific version that will keep the rule that is being exploited. you can choose which version to use. i think on spawning instances until it reaches the limit, but what was the limit number?
 

samspade

Member
the rules are bound to the IDE and runtime versions right? and if i dont update but finish a project in a specific version that will keep the rule that is being exploited. you can choose which version to use. i think on spawning instances until it reaches the limit, but what was the limit number?
Updating may at some point be necessary in order to have a project continue to work and be supported, but even without that it could also be different on different computers or operating systems. Networking would be completely out. I'm not even sure you're guaranteed the same result on the same computer at all times. Relying on undocumented behavior is setting yourself up for failure, and there is literally no reason you need to in this case.
 

TsukaYuriko

☄️
Forum Staff
Moderator
the rules are bound to the IDE and runtime versions right? and if i dont update but finish a project in a specific version that will keep the rule that is being exploited.
Correct so far.

you can choose which version to use.
The existence of certain forced GMS version updates, the last one being 2.1.4, proves this statement to be false. Relying on updates not being forced is about as reliable as relying on undocumented functionality.

i think on spawning instances until it reaches the limit, but what was the limit number?
This is undocumented.
 

TheouAegis

Member
speaking of automation, every programmer pursues automation in coding...
Well, not every one. Automation comes at a heavy cost of speed. We can run parallel processes in some systems, but the programmer is then reliant upon the technician. Without the parallel processing, the program would be required to pause the primary routine and run its cleanup routine to account for all the disorganized coding and memory mismanagement. Game maker's already slow enough as it is; expecting it to derail itself and loop through the ENTIRE RAM alotted and comparing every variable to the id of any instance or data structure that was destroyed would make it run slower than a Tiger Gamewatch.
 

TheouAegis

Member
the rules are bound to the IDE and runtime versions right? and if i dont update but finish a project in a specific version that will keep the rule that is being exploited. you can choose which version to use. i think on spawning instances until it reaches the limit, but what was the limit number?
Since GMS2 requires login, verification and certificate authentication, you can't really rely on it. With that said, you could certainly risk it. I'd call it absafe bet, but not a sure bet.

GM updates because of changes to operating systems and stuff. So depending on what Android, Microsoft, Apple, or Google do in the future, your current version of GM could stop working all together, in which case you might then be compelled to upgrade your version of gm, at which point your code might cave in on itself. Safe bet, not sure bet.

Theoretically, the limit is instance id $ffffffff or even $ffffffffffffffff. Potentially it could be exponentially bigger. I don't remember anyone finding the hard limit and what happens at that limit. In theory, either GM set a hard limit and no new instances are created, GM set a hard limit and the game throws an error, or the id counter loops around and instances have the same id as objects thus causing all sorts of chaos. lol
 
Last edited:

TailBit

Member
I did make a test way back that was gonna check instance id limit, made it so the game disables draw event unless holding a button to draw out results, create new instance, delete old, check for large number change..

It goes real high, then jumps way back into negative, when it get close to the negative version of the default starting id, then it skips over to the positive again and repeat..
 

TheouAegis

Member
I did make a test way back that was gonna check instance id limit, made it so the game disables draw event unless holding a button to draw out results, create new instance, delete old, check for large number change..

It goes real high, then jumps way back into negative, when it get close to the negative version of the default starting id, then it skips over to the positive again and repeat..
It went negative? That's bad. And are you saying you never saw it go between 0 and 100000 (object range)?
 

TheouAegis

Member
or better yet, if (instance_exists(ins)) {};
Nah, that's just going to slow things down. Looping through all active instances twice is only sensible when the first loop fails (noone), but is redundant if the first loop passes. A direct value comparison is better because it cuts out an entire loop.

As long as noone remains the standard and as long as an instance can't have an id of -4 (curious that GM allows -100000), then it's the best method. No more abusing GM's bool handling.
 
Z

zendraw

Guest
Nah, that's just going to slow things down. Looping through all active instances twice is only sensible when the first loop fails (noone), but is redundant if the first loop passes. A direct value comparison is better because it cuts out an entire loop.

As long as noone remains the standard and as long as an instance can't have an id of -4 (curious that GM allows -100000), then it's the best method. No more abusing GM's bool handling.
your sayng if (owner==noone) is the same as if (!instance_exists(owner)) ?
 

TheouAegis

Member
I'm saying owner==noone is significantly faster than !instance_exists(noone). The former compares against 1 value, the latter compares against N values (ignoring the negation). Since N is never 0 in GMS, checking against noone will always be faster.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Not identical, but roughly as similar as reaching into a bag of fruit and checking whether you failed to grab any by looking at your hand and seeing if it's empty and comparing what's in your hand against a list of every specimen of fruit in the bag to see if any of them are in your hand.
 
Z

zendraw

Guest
jesus christ, im asking will it give me the same resault? is !instance_Exists(owner) == noone? i alredy sayd i get that your skipping the loop... and yet again you explain as if im in 3rd grade.
 

Geners

Member
jesus christ, im asking will it give me the same resault? is !instance_Exists(owner) == noone? i alredy sayd i get that your skipping the loop... and yet again you explain as if im in 3rd grade.
Yes, in your case they would yield the same result.

They're just trying to say that the latter would create more overhead.
 

GMWolf

aka fel666
I'm always floored to learn the various ways in which GM is inefficient.
If you have an instance id this suggests a form of map from the instance ID to the actual instance data.
If you already have a map, then checking if a key exists should be relatively cheap.
Why would they loop over each existing Id?
 
Top