• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How do I store an instance id?

C

ChaoticNeutral

Guest
So I tried doing
global.enemyStat[0, i] = instance_id_get(obj_blackOut_b)
and when I used the value, it used the number of the instance_id and not the instance id itself.
what I mean is let's say that the id is inst_19384, it only stored the 19384.
Fix?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Careful, instance_id_get does not do what you think it does. To quote the manual:
instance_id_get


Description
With this function you can get the unique ID value of any instance from the currently active instance list. You give the index in the instance list to get the ID from and the function will return the value for storing in a variable.
Syntax:
instance_id_get(index);
ArgumentDescription
indexThe index within the instance list from 0 - (instance count - 1).
If you're trying to get the ID of a specific instance of an object placed in the room, the function you'd want to use is instance_find.
 
C

ChaoticNeutral

Guest
Careful, instance_id_get does not do what you think it does. To quote the manual:


If you're trying to get the ID of a specific instance of an object placed in the room, the function you'd want to use is instance_find.
Thank you, instance_find does work a lot better but it still only saves the number, so when I call enemystatcount[0, 0] it calls the number, and not the instance.
 

FrostyCat

Redemption Seeker
Thank you, instance_find does work a lot better but it still only saves the number, so when I call enemystatcount[0, 0] it calls the number, and not the instance.
Instance IDs are numbers. What you got is exactly what you should expect. You use them to reference instances. There is no distinct "instance" type.
GML:
(global.enemyStat[0, 0]).sprite_index
 
C

ChaoticNeutral

Guest
Instance IDs are numbers. What you got is exactly what you should expect. You use them to reference instances. There is no distinct "instance" type.
GML:
(global.enemyStat[0, 0]).sprite_index
global.enemyStat[0, 0] doesn't have a sprite index, it needs to be assigned obj_blackOut_b's "instance indexes"
 

FrostyCat

Redemption Seeker
global.enemyStat[0, 0] doesn't have a sprite index, it needs to be assigned obj_blackOut_b's "instance indexes"
Learn the difference between objects and instances. obj_blackOut_b is an object ID. The result of instance_find(), when it exists, is an instance ID. Both of these are numbers, but instance IDs are generally distinguished by being 100000 or higher.

I did not tell you that you must use global.enemyStat[0, 0] to find sprite_index, I only meant to show you an example of how to use an instance ID stored in global.enemyStat[0, 0]. You can use it for other purposes, but at this point you must recognize that you already have what you need.
 
C

ChaoticNeutral

Guest
Learn the difference between objects and instances. obj_blackOut_b is an object ID. The result of instance_find(), when it exists, is an instance ID. Both of these are numbers, but instance IDs are generally distinguished by being 100000 or higher.

I did not tell you that you must use global.enemyStat[0, 0] to find sprite_index, I only meant to show you an example of how to use an instance ID stored in global.enemyStat[0, 0]. You can use it for other purposes, but at this point you must recognize that you already have what you need.
That's not the problem. I know the difference between objects and instance IDs, and what an object and an instance are. The problem is when I store the instance ID, it only stores the number, and no the "inst_" that defines the number AS an instance id
 
H

Homunculus

Guest
inst_SOMETHING is not the instance id, it's just a constant game maker creates for you when you place instances in the room editor, but it just points to the same number you get by using instance_find. Unfortunately, there's no way to get inst_SOMETHING as a string on runtime just by having the id, as far as I know.
 

chamaeleon

Member
That's not the problem. I know the difference between objects and instance IDs, and what an object and an instance are. The problem is when I store the instance ID, it only stores the number, and no the "inst_" that defines the number AS an instance id
That is no different from how x = y stores the value of y in x, not the name y. There's no way to go from a pure value to the "name" of the variable or constant holding it. The inst_whatever is not a thing with properties, it is a constant (I assume. I have never felt the urge to try to assign something to one) representing a number, which in turn is treated as an instance id when you use it in expressions. If you look at the documentation for instances you will notice that instances have no instance_get_name(), unlike resource types which have object_get_name(), sprite_get_name(), room_get_name(), etc. If you need names, create your own naming convention and store the name/id mapping, in whichever direction, in a suitable data structure.
 

FrostyCat

Redemption Seeker
That's not the problem. I know the difference between objects and instance IDs, and what an object and an instance are. The problem is when I store the instance ID, it only stores the number, and no the "inst_" that defines the number AS an instance id
The number is the canonical value, not the name. You got the relationship backwards. For the same reason you should expect a number instead of two letters when you store pi, you should expect a number when storing an instance ID.
 
C

ChaoticNeutral

Guest
The number is the canonical value, not the name. You got the relationship backwards. For the same reason you should expect a number instead of two letters when you store pi, you should expect a number when storing an instance ID.
ok so how would i call the number as an instance id
 
C

ChaoticNeutral

Guest
The number IS the instance ID.
Ok so this is how I'm calling the Instance ID,
This is for the object obj_enemySelect
x = global.enemyStat[0, selection] + (sprite_get_width(global.enemyStatCount[0, selection]) * image_xscale)
this is for positioning the arrow in a spot relative to the instance, but using the value stored in global.enemyStat puts it way off the screen because it's a really high number, so how do I call the number so it uses it as an instance id, and not just a number
 

FrostyCat

Redemption Seeker
Ok so this is how I'm calling the Instance ID,
This is for the object obj_enemySelect
x = global.enemyStat[0, selection] + (sprite_get_width(global.enemyStatCount[0, selection]) * image_xscale)
this is for positioning the arrow in a spot relative to the instance, but using the value stored in global.enemyStat puts it way off the screen because it's a really high number, so how do I call the number so it uses it as an instance id, and not just a number
I've already told you what to do in post #4. If you want to reference a variable from a specific instance, put the instance ID on the left side of a variable-referencing dot and the variable name on the right side. Whether the variable is sprite_index, x or something else, it's the exact same principle.
Code:
(global.enemyStat[0, selection]).x
 

Nidoking

Member
That's a lot of globals. Instances have their own variables, so if you use those, you won't need the globals.

That said, I don't see anything in the line you posted there that would be trying to use an instance ID, correctly or incorrectly.
 
C

ChaoticNeutral

Guest
I've already told you what to do in post #4. If you want to reference a variable from a specific instance, put the instance ID on the left side of a variable-referencing dot and the variable name on the right side. Whether the variable is sprite_index, x or something else, it's the exact same principle.
Code:
(global.enemyStat[0, selection]).x
:/ yeah that worked guess I didn't interpret what you posted in #4 right
 
Top