GML 690 copies of same obj. want suggestions

G

Guest User

Guest
Hi.

I have 690 copies of the same object spread around my room, but I want them to show different things when I click on them, is there an easy way to get gm1.4 to differentiate between the objects when I click on one?

or do I have to do something really long and boring like write a list of 690 object id's :(
 

KurtBlissZ

Member
What are you wanting to show?

Edit: Idk, I'll throw something at ya though... :p

Code:
// Controller/Room Create Event
for (var i=0, _i; i<690; i+=1)
{
    _i = instance_find(ObjNameHere, i);
    if instance_exists(_i)
    with _i {
        image_index = i;
        image_speed = 0;
    }
};

Code:
// ObjNameHere mouse pressed event
switch (image_index)
{
    case 1: show_message("Image Index 1") break;
  
    case 2: show_message("Image Index 2") break;
  
    default: {
        show_message("Image Index "+string(image_index)+" has no action.");
    }
}
 
Last edited:

Bingdom

Googledom
Something like this?
Code:
if mouse_check_button_pressed(mb_left) {
  show_message("Got an ID of: " + string(instance_position(mouse_x,mouse_y,obj_point)));
}
 
G

Guest User

Guest
Something like this?
Code:
if mouse_check_button_pressed(mb_left) {
  show_message("Got an ID of: " + string(instance_position(mouse_x,mouse_y,obj_point)));
}
Thank you! I think as long as id's are static and never change I can use that!
 

NightFrost

Member
Thank you! I think as long as id's are static and never change I can use that!
Bad news is, IDs are handed out to instances in the order they are created, so there is a chance they can change. My approach in code always is that if there is a chance, in long term it is guaranteed. On the other hand there are never two identical instance ID values in game at the same time, so they are good enough as long as you merely need to uniquely identify each, without needing for the identification remain the same across multiple game starts.
 
G

Guest User

Guest
So.. lets say id 10094 which is the object far to the right and at the bottom of the screen, could.. in theory (when I run the game again) be at the middle top?

that kind of ruins my game. damn
 
J

Jaqueta

Guest
What about using the position to create an ID for it? This would make them the same, regardless of instance creation. And each would have it's own ID, as long as 2 instances can't overlap each other, of course.
Code:
custom_id=floor(x+(y*room_width));
 

NightFrost

Member
Yeah, if position is important for identification, you can have the instances calculate themelves a unique custom identifier from their starting position - assuming you won't be creating any more of them at those positions. While it is possible to manually give instances custom identifiers in the room editor, having nearly 700 of them would make it a tedious process so automation is the better way.
 
C

CptChuckles

Guest
you could also right-click each instance in the room editor and manually give it custom values for a variable in creation code \ (•◡•) /
 
H

Homunculus

Guest
You still haven't told us what are those "different things" you want to show. There are a number of ways to address specific instances (keyword: instance, not object), but the solution depends on the problem you need to solve, which right now is unknown to us
 
J

Jaqueta

Guest
^ This

Also, you REALLY shouldn't be using +600 instances...
Probably there are better alternatives such as Maps, Buffers, Lists... However, since we don't know what you are making or want to do, it's kinda difficult to come up with viable ideas.
 
M

mudora55

Guest
What are you wanting to show?

Edit: Idk, I'll throw something at ya though... :p

Code:
// Controller/Room Create Event
for (var i=0, _i; i<690; i+=1)
{
    _i = instance_find(ObjNameHere, i);
    if instance_exists(_i)
    with _i {
        image_index = i;
        image_speed = 0;
    }
};
Don't rely on the order of "instance_find", it can differ throughout the game.
 
Top