Trying to swap instances

I am trying to drag an instance of purplecandy and when it collides with bluedrop it is supposed to switch positions. Most of the time it works. But sometime it doesn’t.

Why do you do this:

straight after starting the dragging?

1 Like

The instances are tight up against one another so as soon as you touch it it will start to collide with the next instance. If I have it so that the mouse is held down and dragged it goes all over the scene.

How do you release the Left Mouse in the Actions?

I tried the following code, it works but not always.

Hi. Great game. The art used in the the game is very nice. I noticed a bug in the game. I have provided the screenshot for the bug in this reply which happens when dragging the candy outside the boundary in which the game is played. If you are working on this game then you should correct this bug. As a developer, sometimes we need to write the whole code of the game again. I don’t know the entire code for this game. I would suggest you to make a code for the four boundaries like using the conditions like the candy objects < right boundary (which is the x position). You will need these four boundary conditions to correct this bug. There is also a bounding box condition which I don’t know how to use but I think it can be used for this purpose which can make things easy.

1 Like

I have tried to add boundaries, but they do not work?

I would like to add boundaries so that only the instance next to the candy is chosen, instead of being dragged all over the board?

Don’t use sub events because they make things very difficult to understand. Use only events one after the other. This is the way I do programming in GDevelop.

1 Like

I am trying to set the boundaries. But still not working?

1 Like

Merge the purple candy is being dragged with purple candy is in collision with purpledown event.

Delete the purplecandy.X()+100,-100, .Y() +100, -100 conditions

Delete the left mouse button was released event, put the actions of this event on top of the actions for the last event which is purple candy is in collision with purpledown event.

1 Like

Eeer… that’s a weird advice :sweat_smile: Subevents are extremelly useful…

It is more “use sub event only if they are executed in the same frame as the parent event, AND while the parent event condition is true”. Indeed the shown example could not work, because you can’t have in the same frame the left button down AND the left button released.


GDevelop has made some changes in the recent updates so you should use sub events to make a game. My games were made without sub events which were made before these updates. With the recent updates a person cannot use variables with events which are repeated. So my mistake for telling not to use sub events.

1 Like

This might be off topic but what do you mean. I’m not aware of any change like that.

The only change with variables that I’m aware of is that if you declare them with the setup screen then instead of using Variable(a) or VariableString(a) you can simply use just a in most places.

That greatly increases clarity by being able to u
make formulas without all the Variable() expressions in between.

a * b + c  

is so much easier to understand


This was a big mistake from my side. I don’t remember exactly but I read something about it in the updates in what’s new improvements, etc and I was recently testing this game with this code to help-

I thought this code should drag the object again and again but it doesn’t. There is something wrong in this code.

After seeing your message I tested this new code which works fine with the variables-

Thank you for correcting this big mistake. I think I am a fool with this mistake. I have been away from GDevelop for some time and I have forgotten some things in GDevelop. Thank you very much.


That’s one thing I haven’t tried yet, TopDownMovement. Maybe next game.

Have you found your solution ?
With your first code sample, have noticed if the issue depends on the direction in which the collision is made (from left or the right, or the top, or bottom) ?

I wonder if the way rounding works in the snap function could have the 2 objects landing in the same cell.

1 Like

I have another thing wrong with my code, sometimes it swaps the instances and sometime it doesn’t. So there is a blank spot, with the two instances in the same place??? The boundaries still don’t work???

I tried the game on my ipad and the floating screen would disappear everytime I swiped down??

Have you seen this project?

It might save you a ton of time creating your game.

1 Like