GMS 2 How to combine nearby similar objects?

okAi

Member
Hey, I'm trying to figure out a way to detect or combine all nearby similar objects, and be able to edit them as a group.

Capture.PNG
For example, If I wanted to delete objects 1, 2, and 3, (which are all the same object) I would be able to do so by having them know which one is nearby the other. So, deleting object 2 would also delete 1 and 3, since they are touching. Objects 4, 5, and 6 are also the same object, but since they are not touching, they are not effected.

The only way I can think of doing this is by having some recursive script do something like:
GML:
Script1
//Pseudo Code
//Look for and delete nearby similar objects

if(place_meeting(x + 40, y, obj)) //if there is a similar object to the right (check other directions too)
{
    //Check for nearby objects of this
    script1(obj)
    //Otherwise, delete this object.
}
But, this seems like an incorrect method, while also being above my skillset to write effectively.
Only other things I can think of are renaming the objects to be similar, but I think that causes the same issue.

Is there a solution that I am overlooking?
 
Do you mean like Tetris? Because if you're doing any kind of Tetris, Match-3 and stuff like that, it would be much simpler to not use objects for every block, but only data on a grid.
 

woods

Member
maybe checking left and right for the object, and then destroy all three of them?
something like..

if ((place_meeting(x + 40, y, obj)) && (place_meeting(x - 40, y, obj)))
{
with other
{
instance_destroy();
}
instance_destroy();
score += 100;
}

might want to look up some match three tutorials for this ;o)
(beyond my scope as well)



edit:
dont listen to me... slow fingers has better idea and more knowledge ;o)
 
Last edited:

TheouAegis

Member
How are you grouping them? Arbitrarily just based on proximity? Or are they spawned in as groups? If you insist on objects, assign a "group" variable to all objects inside a group when they are spawned.
 

okAi

Member
How are you grouping them? Arbitrarily just based on proximity? Or are they spawned in as groups? If you insist on objects, assign a "group" variable to all objects inside a group when they are spawned.
They are grouped if they are all touching.
To be more specific,
There are groups of grey colored objects, that when my player runs into them, I want them to change color only within that cell. (Cell being all other touching grey objects)
But the other grey objects within the room, (that aren’t touching) shouldn’t change color.

Would assigning a group variable go into their creation code for the room? If so, how do I call it?
 

okAi

Member
The objects wont move, they are static. They are wherever I placed them within the room layout.
 
Top