• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

SOLVED Preventing layered objects?

Dsharp

Member
My understanding is that GMS 1 had a 'delete underlying' toggle that would prevent you from accidentally stacking objects on top of each other when placing them in the room. However, it seems this was tossed out in GMS 2.

I found an old topic on the subject suggesting using this line of code:

GML:
if (place_meeting(x, y, object)) instance_destroy();
to delete any accidentally-stacked objects. And this works well enough.

But I hate the idea that my game could be full of stacked objects that are always being called and then deleted at the beginning of each stage. I could of course add some more code to the above example, maybe I could color nodes in that If statement so I can identify and weed out any stacked instances.

IDK, it's been over 3 years since that old thread was made - is there really no way to just tell GameMaker not to allow me to accidentally do this in the first place?
 

TsukaYuriko

☄️
Forum Staff
Moderator
While there seems to be no such feature as the old "delete underlying", instead of just destroying duplicate instances, you could output a debug message showing the instance's coordinates. That should simplify nuking it in the room editor.
 

Dsharp

Member
While there seems to be no such feature as the old "delete underlying", instead of just destroying duplicate instances, you could output a debug message showing the instance's coordinates. That should simplify nuking it in the room editor.
Right, so similar to what I was thinking of doing, but with coordinates instead of colors. I can do that, and it's not the worst thing in the world or anything. I'm just a bit confused why they'd get rid of this feature. Are the GMS 2 team just precision gods who have never accidentally, say, tiled a wall over another wall while using the ALT key to mass-place objects? Did they never foresee that feature being useful in GMS 2?

I know tilesets are also a thing, but it's my understanding that you'd still have to place invisible objects over tiles to assign properties, right? Which could result in this same problem? Maybe I'm wrong, I've only been at this for just under 2 weeks. It just seems like this issue would've come up before, unless I'm just building my rooms in a way that I'm not supposed to.

Either way, thanks for your help. I guess I'm just kinda in disbelief that there's no way to prevent this issue in GMS 2 like there apparently was in 1, and it makes me wonder if the GMS 2 devs expect me to be using some other paradigm to create my rooms that bypasses this issue.
 

TsukaYuriko

☄️
Forum Staff
Moderator
You can handle collisions vs. a tile map. There's no need for instances for this.

Also note that GMS 2 is a complete rewrite of GameMaker, so it's less of a "feature they got rid of" and more of a "feature they didn't add (yet?)". If you'd like to see it added, please file a suggestion.
 

Dsharp

Member
Right, there's collision, but my game's a turn-based, grid-based strategy game, so I need my nodes to have a lot more information to them. I don't know that there's a way to store all that information in a tileset tile.

Either way, I think I'll file a suggestion, yeah. Good call on that, thanks again!
 
Store information in a ds_grid. Then reference that grids coordinates whenever you encounter a collision with a tile. Stop thinking of instances as the only way to process stuff, it's almost always WAY more efficient to build a structure yourself and process that structure than using instances, as instances come with a LOT of additional baggage that custom structures don't (memory use, cpu cost of checking events, etc).
 

Dsharp

Member
Store information in a ds_grid. Then reference that grids coordinates whenever you encounter a collision with a tile. Stop thinking of instances as the only way to process stuff, it's almost always WAY more efficient to build a structure yourself and process that structure than using instances, as instances come with a LOT of additional baggage that custom structures don't (memory use, cpu cost of checking events, etc).
Right, sorry, I haven't gone over the full details of this code yet. I'm working on the DS_grid, the tutorial I'm following is using another data structure (2D array/list), but I've decided I wanted to use DS_grid after looking into it.

The point is, in order to easily create maps, the tutorial I followed used a system where they'd place objects in the room editor and then delete them, using the object to populate that node in their 2D Array (soon to be DS_grid).

Kinda getting off-topic now, but if something like that were possible with tiles that'd be fantastic. The reason I'm not using tiles now is I'd have to have both the visual tiles on my map and the ds_grid storing the information as separate things. I'd have to manually input which cell should have what properties, and if I make a mistake there'll be a discrepancy where maybe a wall tile is a forest tile.

Again, not the worst deal ever, but I figured this way of doing things was less risky.
 

TsukaYuriko

☄️
Forum Staff
Moderator
You can certainly have multiple (invisible in-game) tile layers on which you can place specific tiles which write appropriate info at corresponding positions in some structure of sorts... ;)
 
There's a very easy way to get the correct coordinates. Setup the grid so each cell is the same "size" as your tile size:
Code:
tile_size = 32; // 32x32 tile size here
ds_grid_create(room_width div tile_size, room_height div tile_size);
Now whenever you need to convert from a position in the room to a position on the grid, you simply do this:
Code:
grid_x = room_position_x div tile_size;
grid_y = room_position_y div tile_size;
So, when you're storing information from the instances you've placed in the room (where previously you were populating a 2D array), you'd call the above code for the instances position and now you have the correct cell in the grid (the exact same process could apply for a 2D array, just grids have a little more functionality). Then whenever you have a collision, you call the same piece of code above again, using the collision coordinates for the room_position_x/y and you'll know which cell you need to grab data from for the collision.
 

Dsharp

Member
I think I get what you're saying - if I am, it's similar to what I'm doing now, just with tiles instead of objects. I need to play around more with both collisions and tilesets first.

Thanks both of you for your help. I'm glad you're confident that this is possible with tilesets, saves me a lot of trouble.
 
Top