Hey guys, I've created a drag-and-drop sliding tile puzzle minigame that I'm setting within a larger RPG level. It is mostly functional, however, I have run into a behaviour that seems to occur somewhat randomly that breaks it. I'll explain my workflow:
I first created an invisible grid on Layer 0 with placeholders 1 through 9 ("Place1" to "Place9"):
I then inserted my image as a sliced sprite animation set (speed set to 0) and scrambled it on the grid on Layer 1:
I put together code which does the following:
-Assigns each piece of the image a number (as an instance variable) according to which tile it is currently on (every tick).
-Checks each piece (on DragDrop > Drop) firstly which piece it is (according to the variable), and secondly where it can be placed.
-This is done by checking firstly whether that piece is overlapping a particular "Place#" on the grid, and also if that particular "Place#" is empty (with a variable 1 or 0), and then setting its position to the x and y coordinates of that grid place. In the same event I include actions to set the destination place to "Full", and the source to "Empty".
-An else statement underneath the possible locations sends the tile piece back to its origin (in the case it is dropped in an invalid space).
-I also have code regarding winning conditions, but they don't concern me right now.
Here's my problem:
When I move two or three tiles, everything seems to be working fine. Then I will try to drop another tile on an empty space, and it springs back to it's origin. This might be fine (assuming it just hadn't overlapped properly or something), but it also seems to set the "Full" variable of the destination to 1 (on), even though it has sprung back to the origin. With the empty space "Full", no tiles are allowed to move there, and the game is broken.
My code is attached, if anyone can help me reorganise it to solve this issue, I would be stoked.