[SOLVED] How to pass adjacent object value to neighbor object

Damn it was hard to explain it in title
Better luck with screenshot below


As you see i have red and blue circles
They have different amount of dots
Dots can be represent by animation or variable
And for example on top you green rectangle with blue circle which have 1 dot
Now i would need it to pass that info to red circle in that green rectangle
And so red circle with 3 dots should receive info that right from it there is circle with 1 dot
Where in white rectangle i have blue circle with 2 dots and i want to pass that info to red circle with 3 dots in white rectangle that right from it there is blue circle with 2 dots

Once i will be able to check right from red circles i can replicate it for other directions
So for now yellow rectangle does not matter

Red and blue circles are separate objects
Amount of dots are different animations
So 1 dot is animation 0 and 2 dots is animation 1 and so go on
I also have number variable on each circle which represent dot count for each piece

I just need to either pass info of animation or variable from blue to red circle

In this case to the left from blue circle

I want to avoid creating custom points in object properties
I did try using bounding box and point inside object but it did not work for me
My worst idea and last resort is to fire bullets from each blue circle
And delete them if they hit red circle or travel one tile space (Tiles are that yellow squares or you can say board)
And before i delete them if they are in collision with red i would simply do same crap as you would do with HP
But in this case i would add to HP variable of red circle instead of subtracting from it
Where before that i would set HP to 0
So blue circle with 2 dots would fire bullet to the left with animation corresponding to dots of blue circle so 2 and that is how i would know red circle should get 2 HP
Meaning i would know right from red circle there is blue circle with 2 dots

BUT i believe there is a way to do it without creating separate objects
I just can’t picture it so i came here to ask for ideas

Any reason for this? Because it was the first thought that popped into my head. You can then use the “point in object” expression. Simple and straight forward.

Otherwise you could hardcode the point’s offset relative to the object’s centre.

1 Like

I want to contribute this game as template
And i want to require users to do as little as possible
Going for preparing custom points for red and blue pieces is kinda last resort for me
Look i won’t explain you the rules
I will only tell that green button is reset button you click it to toggle AI OFF and ON which is indicated in text
You hold it until shapepainter cover whole board with black color to reset scene
And you will understand rules in no time where game name is Expand When Four so it is that simple

Anyway this is how much objects it have

Its that minimal so it would be easy to shove in to anyone game as minigame
And all im trying to do is you just go copy whole events group for that game paste it into your game and generate at best only 3 objects Tile (board yellow squares) and blue+red circle pieces with 4 animations
And that is all you will need to do to adapt it to your game

I can go for custom points but from my experience it is better NOT to require ppl to do additional steps since ppl make mistakes or do not understand what they are asked to do
Like saying “double click blue piece and click on edit points and add 4 custom points in each direction for same distance as piece width or height is” for you and me is easy while many new users will get confused
And will not understand what they need to do
VS
Copy paste this whole group into your game
And just add 3 objects is A LOT easier for any user to understand
I hope you get my reasoning now
For myself i would be perfectly fine with custom points
For general use for users with different knowledge it would not be best idea

Anyway i did try this


And it is not working

I was trying to replicate this

But either i did it wrong somehow or it works only because it was for extension and i have 2 ways to reference same objects as Object or as Tile

I am open to any ideas

Excellent game. Love it. I don’t know if you saw this post.

https://forum.gdevelop.io/t/collision-instance-and-animation-solved/57043/8?u=keith_1357

I used a sprite with a plus shaped collision box. IDK how you’re doing your checking but the array technique would also work beautifully. I originally found it while playing with a classic pipe game.

Thanx but you did not read or understand my message above
I am trying to avoid using extra stuff that needs to be done by user cause i wish to contribute it as game example for gdevelop
So any user can just copy whole events group and paste it to their project
Where in editor all that is required is to create 3 objects yellow Tile square objects which creates board and red and blue pieces
And that is pretty much it
I do not want ppl to be forced to edit their points or collision mask or go with extra objects
For me that is last resort
Where i could simply create bullet object and fire bullets in each direction with variables holding their direction and amount of dots of piece from which they were fired
Before that i could set HP of each piece to 0 then add to HP Left HP Right HP Top HP Bottom variables of each pieces depending on what did hit them
But again i am trying to avoid adding extra stuff so it is super easy to adapt it to your project
The process can be convoluted to the sky for all i care
As long as it does not involves doing anything outside of events sheet
Cause no one gonna modify events they just gonna copy them
I just gonna leave few variables which any1 can adjust like how long it should take AI to make a move
How hard AI should be and speed of pieces moving when expanding
And i have perfect idea how to do it i even found how to make AI more evil
Like run the game and hit reset button to disable AI
And you now control both and red pieces
For one pieces go with whatever you want but for others follow a rule
ALWAYS pick piece with lowest dot count that is not direct neighbor of opposite color pieces
As your default choice
But ALWAYS give priority to if your piece with 3 dots is direct neighbor of opposite color pieces with also 3 dots and your turn just started

That is enough for making game last longer while making it tricky enough for players not win so easily

BUT only thing i do not know is how to pass information about dots to opposite color pieces via events without involving editing anything in scene editor or adding extra objects

1 Like

OK. Here is a list of ways.

Ray cast in each direction 0, 90, 180, 270
Point is inside either from edge or +/- grid size
X() = X() +/- grid size
Use a 2D array or structure grid[0][0]
Object variables of the tile could mimic an array if they had a column and row object variable you could pick the tile and either read a variable or check for a collision

Just ideas.

By this you mean X and Y?
Cause if so i think that would be easiest thing to achieve for me
I just still don’t know how would i pass blue piece variable which is at X 200 Y 0
To red piece that is at X 100 Y 0
All pieces are even size so all i need to like go 1 grid space to the left right top up and send info how much dots have one that is sending it
And then only send it opposite color pieces
BUT i think it would not matter which would get it
Since at beginning of the process i would set them all to 0
And in turn of red you can’t click blue and vice-versa

Also how would i go point from edge if i do not define points?

The edge is defined by the bounding box.

The array would be X, Y or colum and row using the tile object. You could assign a row and column variable to the tiles and use it for reference. A structure or arrays of structures would work. Or the tile themselves and check for collision or point is inside or an object variable.

Click tile get tile.column and tile.row
Pick neighbor tile by checking tile. row = row - 1

I did try this and it didn’t work

As for going with X and Y i can check position of something
But i don’t know how to pass information of specific piece in that position to piece in 1 grid space distance in 4 directions

I would need example for both cause i lack knowledge here

It would depend on any conditions. If the condition used the group name then only the object that was interacted with would be picked even if they’re different objects.

You could save the center X, Y and use pick all but the original object wouldn’t be picked. So, the bounding box wouldn’t work but you could use grid width and height spacing variable from the setup.

Let me grab something to eat. I’ll then try to get to my PC. This is all theory and there might be an easier way. It’s just more difficult when you’re not the user. You need to plan for any possible size or spacing or even for rectangular tiles and pieces. Everything needs to be dynamic.

It’s an interesting project.

Edit
I think casting a ray would be the easiest way when not knowing the actual distance. Set a large enough test distance and the neighboring objects could be 1 pixel away or 1,000 as long as it’s inside the range.

Save the current center X and center Y and the object playerID
Pick all
Group playerID variables ≠ playerID
Ray cast against group 0° distance 100

This would compensate for the different size objects and spacing.

Again. Let me do some testing.

But when at least 1 Well actually 4 pieces exist when it would be AI turn and i would need that condition
So it would be either piece width or tile width as distance since they are the same size
Where they all are on grid next to each other with no gaps
I simply made their images with some gaps
And board will be created via events
Right now it is only placed manually in editor
So using either tile or red or blue or pieces (red and blue object group) width or height (even images so same value) would work for checking distance

EDIT: I’m at my PC and I see my logic was flawed. You need to find neighboring Tile objects not pieces. I’m playing around.

I’m still not at my PC but I did this on my phone. The Or event would allow for all of the neighboring objects to be picked at the same time. A picked object variable is used to filter out the picked object because the ray is being casted from the center of it without filtering out the object it would only pick that object.

This uses a touch condition but any condition that picks 1 object would work. Along with X and Y you would need to save the player ID of the piece so you can change the adjacent pieces to that player if the selected piece has a certain dot count.

You would also increase the dot count first and only do the ray cast part if the object had the right amount of dots.

Depending on your actions, you might need to add a for each object as a sub event of the ray cast event.

When I’m at my PC I can make a more detailed example.

Ok, here’s a crude mockup of my interpretation. It doesn’t check for the object that it’s colliding with so it eventually kind of goes into an endless chain reaction. Also, I think I have the count wrong and it should spread out a click earlier.

I used images of numbers for testing instead of dots. You also can’t add the first object.
https://gd.games/keith_13579/picayune-calculator

project (click the green [code] button and [download zip] then extract and open the JSON file
https://github.com/doug13579/gdevelop—tile-game

Events:

Yeah, I think value equals 4 should be 3 as highlighted

1 Like

I am not sure if this is what i did ask for
Maybe i just explained it poorly
I didn’t have even time to test it
Right now its 2 am and i finally have a moment to check this out
But as i read trough your events i am not sure it will do what i want it to do

You see my game works fine nothing needs to be fixed
Only thing i wish to improve is how AI is picking what piece to click
Right now i am going for random piece with highest dot count

Where what i want to do is for AI to always go for 3 dots piece when it is AI turn and next to it is 3 dots piece of player
Meaning AI piece will expand (pieces with 3 dots when clicked gets 4th dot and expand into 4 pieces with 1 dots going up down left and right)
Claiming player piece in the proces
That is only thing i need
BUT only part i miss is how to make game check where is red (player) piece with 3 dots next to blue (AI) piece with 3 dots
So AI can pick that piece
For that i would need a way to send for example variable to piece on the left from red piece one grid space ahead and i could call it lets say DotsLeft
Repeat it with DotsRight up and down so i have 4 vars
Now i could check IF any of that var is equal to 3
And if so it would mean for AI that there is 3 dots piece next to it
I could make collision check but that would allow diagonal check
Where diagonal neighbors would have no value for difficulty of AI
If i disable checking collision by touching with edges then i would be back to square one since none of the collision would work or i would need to edit collision mask which i try to avoid

While i was writhing above i was testing some crap
I was testing raycast
I could not get it to work properly
I never used raycast and i am bad with arrays
That’s why i wanted to get raycast to work 1st
And i found this raycast example GDevelop 5
By modifying events a little and adding instance copy of player on scene (basically i just added for each event for player and disabled inverted raycast event)

I was able to get it to work in my game
With

And get this

As you see i am able now to get animation and variable of each piece and do various stuff depending on that values
For example 3 dots tint to red where 2 dots tint to blue
Pieces are managed by Dots variable and animation index is changed to value of Dots variable
Now its time to make some evil AI

@Keith_1357 WTF!?


THIS?
When i only needed this for one direction

WTF!?
Damn i haven’t that good laugh for a long
You made my day and taught me again to not be afraid to try stuff out and learn

@Keith_1357 @MrMen I really do not care what you will think but i love you 2
I help ppl on discord i help ppl here but when it comes to save my ass i always see one of you as author of reply
I hope one day i will be able to solve your problems if you have any

2 Likes

Just an update for curious ppl
Now for WTF ever reason
It works even with checking point inside object

I mean i do get it i previously was checking group and not specific object BUT COME ONE

Hey i read your original post and how you want to make it beginner friendly.

Heres my simple way of checking if an objects is near another to pass things to it.

  1. Create a “Checking Object”, just a simple little object
  2. When wanting to check if an object is next to another, simply create the “Checking Object”, and if its in collision with an object, then do what ever it is you want it to do.

Its simple and easy, it uses basic concepts like creating objects and checking for collision, so should fit what you were trying to do in the first place.

  • I have seen you insulting other users here
  • I have seen you not reading what users ask for
  • I have seen you just throwing random comments which you think fit topic which do not cause you did not read what was asked for
    Which you are also doing right now
    I see no value in your messages i just gonna block you

Just so you can understand what you just wrote

  • I literally did explain i could create even a bullets give then pieces HP var and add to HP var depending on from which side bullet hited piece
    So you just described what i already had as last resort solution
  • I did say i do not want create additional objects since i could simply do it via objects i have already just give them different purpose when i want to add dots for AI to be able to measure them
    Like use pieces with 1 dot on beginning of turn to pass some variables instead of creating separate objects

Its simple and easy
You just need to read carefully before you reply with your ideas that are not related to problem to be solved
Farewell

That is one angry cookie… the man needs to chill out lol