How to select a specific object.id, instance.id? [SOLVED]

Bryan112

Member
Hi, I'm new here.

Hope you guys are feeling alright.

Anyway, perhaps you guys can help me.

TLDR: How to select a specific object.id, instance.id?

I made a cool looking inventory system. You can drag and drop items into crates and/or back into your own inventory. The crate to inventory part is working like a charm, however. The inventory to crate part is where it gets tricky. It is possible to have multiple crates in your world. To drag and drop from your inventory to a crate, I need to select THAT specific crate only.

What I have now: (BE AWARE THAT THIS CODE IS CALLED FROM THE CRATE SCRIPT) Ocontrol_inventory.CRATESELECTED = object_index;

(Ocontrol_inventory being the player inventory object.)

Sadly this doesn't work. When I'm testing the code, the object_index I'm looking for doesn't get found. How do I fix this?

Does this have to do with instance_id? Object_id's? Is till can't really tell the difference between the two.

Thanks a lot!
 

Ommn

Member
If you only have one instance of the object in the room
you can call by object name like this:
GML:
with(obj_player){if global.selected==id
{

}}
or
GML:
if obj_player.id==global.selected
{

}
 

Nidoking

Member
The difference between objects and instances.

Needless to say, this is a vital concept. You can't expect to make games if you don't understand it. Hopefully, that thread will bridge the gap in your understanding.

Ocontrol_inventory.CRATESELECTED = object_index;
Here, in particular, object_index is the type of thing. It is an identifier for what a crate is, just like "house" is an identifier for all houses, and if you want to describe a specific house, you would need the address. The instance id serves the purpose of that address. It tells the game which specific crate you're talking about. Since you're running this inside that crate instance, the variable you want is "id".
 

Bryan112

Member
The difference between objects and instances.

Needless to say, this is a vital concept. You can't expect to make games if you don't understand it. Hopefully, that thread will bridge the gap in your understanding.



Here, in particular, object_index is the type of thing. It is an identifier for what a crate is, just like "house" is an identifier for all houses, and if you want to describe a specific house, you would need the address. The instance id serves the purpose of that address. It tells the game which specific crate you're talking about. Since you're running this inside that crate instance, the variable you want is "id".
GML:
Ocontrol_inventory.CHESTSELECTED = id;
works!
Thanks a lot. Really appreciate it!

It indeed is a vital concept of making a game, and thankfully you explained it to me like a 5 year old. lol, i needed that
 
Top