Check if instance does not exist at position

I believe that might be simple, but i’ve been trying to wrap my head around that one, how do i check a position to see if there’s an object there? I’m creating a random dungeon generator and i want to fill the ground with walls around it, but apparently there’s no way to check if there isn’t an instance at a certain position, i’ve been using “Point inside object”, but i couldn’t really make it work, i’ve tried to invert the condition but that doesn’t work at all.

Here’s what i’ve tried to do so far:

This repeats for all 8 direction close to the tile, but the walls are place inside the tiles nonetheless, when this condition is inverted it just don’t work, i’ve done something similar with my character movement, they can only move inside the tiles, but when i revert the condition they move inside and outside the tiles as if the condition, while being reverted, doesn’t work at all.

To simplify your conditions: Add your tile types into a “Tile” group. Then you can just have 1 line targetting all of the tiles instead of 1 for each tile type.

And then you might try using “pick nearest object” with that group.
Then you can just do a number comparison of FloorTiles.X() - 16 is inside “Tile” group. I think. Maybe. Probably. :smiley:

(Worth a shot)

Hello! Thanks for the help but i already did the group, i moved back from the group to individual objects within an “or” to see if it would change anything.

The group FloorTiles contain Room_Tile and Hall_Tile, while the group Tiles contain all 3 of em. What i did before was a check if “FloorTiles” was inside “Tiles”, pretty much the same thing that’s already here, but no luck.

Also, what do you mean by using “pick nearest object”? I mean, i know what it is, but how exactly was your idea to use it here? I’m sorry, i didn’t get it.

There is a Pick Nearest Object condition.
Use that, and for X use FloorTiles.X() and for Y use FloorTiles.Y()

Hi! Yes, i know about that condition, i just don’t understand how to use it in this particular case.

I mean, what would be the purpose of using it here in this case?

I think using “Pick nearest Object” and selecting the “Tiles” group would allow you to find the closest object to your current floor tile and select it.

By selecting the nearest object, when you do a “Compare position of object” or anything that targets Tiles, it will use ONLY that nearest instance of tile.

There are some oddities when using Group.X() or “AnyObjectOfThisname.X()”, but by using pick nearest object it should remove those irregularities.

1 Like

I think i understand, you’re telling me to pick through “Pick nearest Object” the tile that’s nearest to the current selected tile, right? The problem is that i want to do the opposite, i want to ignore those and pick the spaces that has no instances on.

That’s easily doable with the same process.

After picking the nearest tile, you just invert your “is X within X” condition.

If the nearest tile isn’t in that X, then you know there’s no instance on it.

Is this what you mean?

English isn’t my main language, so i’m having a bit of problem to understand, thanks for the patience.

I think you’re pretty close. I believe you need to make your Inverted event and Create object as a sub event.

First event

Repeat for each instance of FloorTiles
Pick the Tiles that is nearest to FloorTiles.X();FloorTiles.Y()
Trigger Once

Sub event

(Invert) FloorTiles.X() + 16;FloorTiles.Y() - 16 is inside Tiles  ||  Create Object Wall_Tile at position FloorTIles.X() + 16; FloorTiles.Y() - 16
Trigger Once

I think that should work. Also, using 2 trigger once saves you a sub event, but it’s whatever you prefer.

Tested it here, but it still don’t work, the walls are placed on the 8 direction of each tile wether it has a FloorTile on it or not.

Could you test and see if the Inverted “Point inside Object” works with you? It doesn’t seem to work for me in any kind of interaction i use it, meanwhile the non-inverted “Point inside Object” works just fine.

I can’t get it to work either, so there’s likely something wrong with my logic or understanding of how it works.

Just to check, have you tried just using a Collision event instead of “is inside”? The goal is to have your walls touching the floors, right?

Would “(Invert) FloorTiles is in collision with Tiles” not work? (it can take into account touching surfaces, not just items that are inside each other)

1 Like

I believe it would be a bit janky because right now every tile is checking all the eight directions around it (-16 -6, 0 -16, +16 -16… etc) so after the very first wall gets placed, that tile is now colliding with a “Tiles”.

Edit: maybe i could test a collision with an “And” and check the position of the “Tiles”, that could work, let me test it.
No, still doesn’t work, but i guess it makes sense since most of the time it will have multiple collisions

Thanks for all the help Silver-Streak.

If anyone’s reading this, i ended up making an array with structure notation and added the x.y of the -to be generated- tiles, then did a quick check on every tile of the map through a while loop and added the instances there.

1 Like

Glad you found a solution. Sorry I wasn’t able to help further.

It might be worthwhile to throw up a screenshot of your events for your solution (if you don’t mind) so other people can learn how it is done in the future.

The code is part of a bigger, messy code, so yeah, i’m fine with showing it, but it’s too messy to show right now, i could clean it up later and post on the forum.