How to drag a line along a grid? (Flow Free-like)

Hey all, I’m trying to create a game similar to Flow Free. What I can’t figure out is how to make the game itself work.

What I have here are the hearts which are to be connected together by one line, and a grid. What I thought of doing was having an object for a dot, which display at the coordinates of the heart you hold left click on, and a line, that displays on each box you go through as you drag your mouse. I already have an object for the dot and for the line.

That’s where I get a problem, this doesn’t seem to work;

665;67 is the position of heart_purple_1 which I assumed should be where the object dot would be created. Does anybody have an idea how to do this correctly? Or better yet, do it in a better, more efficient way? Many thanks

Was the problem that no dot actually appeared?
I can think of 2 things that could’ve gone wrong: either the Z order of the dot object was lower than that of the heart object, causing it to appear behind the heart, or its color was the same and it couldn’t be seen.

You can look at the Z order of an object by right clicking its sprite in the scene editor and opening its “properties” menu.

Since I don’t know of any behavior which adds programmable colors to objects, what I could suggest is having different “line” objects for each color.

You could also make every cell an object and assign coordinates to them based on their relative offsets in the grid, that is: don’t use their actual coordinates, create your own coordinate attributes for the cell objects and have the top-left cell be 0;0, the one to its right 1;0, the one below it 0;1, etc.
You can also create the grid dynamically when the program starts, via an event, so you don’t have to set these grid-coordinates for each manually.
Then, if you register the cell that was last clicked on as the active one, on each click, you could check if the newly clicked one is a neighbor of the active cell, by checking whether only one of the “GridX” or “GridY” (let’s call them so) attributes differ, and only by 1.
If the “GridX” coordinate differs, you have to draw a horizontal line, if the “GridY” one does, a vertical one.
I assumed here that only neighbors can be connected by the player with a single mouse click.

Remember that I’ve said above that you could have 1 line for each color? If you have, let’s say, vertical lines, you could rotate them by 90 degrees on creation in the scenarios where you need horizontal ones.
If this looks bad due to the asymmetric form of the hearts, you might have to think about adding 2 separate line objects for each color.