I am still perplexed about every instance of group condition and sub-events

This may be lazy coding from my part but what I am wanting to accomplish is basically comparing every instance of three groups with each other.

The first block of code snaps the hover block to grid.

The next line of code is supposed to check whether the tiles’ position matches with either grey or blue units. If they do, it is supposed to put the object name into the tile variable (this is going to be useful later down the line).

However, I am unable to accomplish this and was wondering if it is not possible in GDevelop to compare the XY position of two groups (with multiple instances).

Screen recording 2025-02-09 12.14.58 AM

If you want the tile to have the type of the piece in it then you could create a group with all of the pieces then use a for each object and point is inside.

For each PieceGroup
----if point PieceGroup.CenterX(), PieceGroup.CenterY() is inside TileGroup

Then set the TileGroup variables based on the PieceGroup name or variables.

In the future when you move a piece just do the same without the for each object.

1 Like

Hi Keith,

Thank you so much. I understand that. And I have come up with a different way of addressing the problem. I am just trying to understand the fundamentals and figuring out why the above logic did not work.

Do sub-events within for each instance of object or group not run in the same manner?

Sub events work the same. The for each object just picks 1 object at a time.

The conditions in 1 event of

A=1
B=2
C=3

Would be the same if they were all subevents.

A=1
---B=2
------C=3 

I think your concept seems OK. It would just be more efficient to do the pieces since each piece is in a space but each space probably doesn’t have a piece.

Also, while blue is changing grey will be the same. So, until blue changes, there’s no need to check for grey. An vice-versa for the grey.

A slightly better strategy might be

For each tile
--for each grey
--for each blue

Say you had the following objects
a1 to a3
b1 to b3
C1 to c3

If the for each objects were all nested

For each a
–For each b
– --for each c

The sequence would be

a1, b1, c1 thru c3
a1, b2, c1 thru c3
a1, b3, c1 thru c3

a2, b1, c1 thru c3

And so on…
Each time one 1 of each object would be picked.

If it was

For each a
--for each b
--for each c

It would be

A1, b1 to b3
A1, c1 to c3
A2, b1 to b3

And so on. There wouldn’t be so much repetition. You would split the comparison conditions inside the related for each object.

Although, I still like my original idea. Although, I’m not sure if it meets your needs.

A more efficient way is to just update the tile names as you move the pieces.

I don’t know how you’re placing the pieces. Where are the origin points. Personally, I would put all the object origins to the center. Unless the piece and the tiles are the same exact size.

You need to make sure both the tile and pieces are in the exact same space. Even a variance of .00001 would throw things off. Because 10 is not equal to 10.000001

I’ve had times were the pesky floating point error caused issues.

1 Like

Thanks, Keith. I am still perplexed then why it doesn’t work. You are seeing in the video that it is not. You are also seeing in the video that X and Y are exactly the same (with no floats). Yet, it does not show the object name in debugger.

I actually just ran a test to confirm that it all sub-events do work - although there are repetitions :).

Why do these variables have ToString()?

Are the variables numbers or text?

I think that’s the issue and GD should probably give an error that you’re trying to convert text to a string which if it’s expecting a number would probably fail and return 0. Try removing the 2 ToSting() expressions.

1 Like

Oooh, I will try it tonight and report back. If that is it then I would be super happy.

1 Like

OK I tried it. I removed the ToString and it is working like magic.

Thank you so much, @Keith_1357.

ezgif-40717dd0ae1537

1 Like