Trying to swap instances

I can understand that…

If it helps :

  • The eventsheet is read every frame (60 times per seconds), from top to bottom.
  • An event (a line) is made of 2 parts :
    • the left part, the condition(s),
    • and the right part, the action.
  • If the condition(s) is true, then the action is executed.
    But the condition does something else very important, which is Object picking ! Consider it like a filter : only the objects which have been picked (for which the condition is true) are available to the actions on the right side.

For exemple, if you check the collision between the PurpleCoin and the GreenCoin, on the right side, the actions will be applied to the Purple et Green coins which collide.

  • Now come the subevents :
    A subevent is only tested if the condition of the event it is attached to is true.
    AND it is only applied to the objects which have been picked in the event it is attached to.

For exemple : a subevent attached to the one described previously, will only perform the condition on the Purple and Green coins which collide (which had been picked in the previous event).

  • And this is a huge difference with an new event, created below another but which is not a subevent ! Contrary to a subevent, this new event would be tested independently of the previous one (whether the conditions of the previous one are meet or not), and it will take into account every objects (the object picking from previous event is reset).

Said differently : a condition also filters the objects available for the actions. A subevent adds a new filter to the previous one, while a new event (which is not a subevent) resets the filter.

I hope that it makes sense :sweat_smile: It is a key concept in Gdevelop, which is easy to miss when starting. And which very different from most other programming tools.

1 Like

Hi, I moved this topic to the correct section of the forum “Gdevelop general / How do I…?”

1 Like

Wow wee I have to try it out, tomorrow. Thanks for all your help.

This seems to work better, but still stops working sometimes???

I thought the first global variable EndX and EndY would record the first position of purplecandy, but it follows purplecandy and returns the position of where purplecandy ends up. The the second global variable StartX and StartY records the first position of purplecandy???

I tried my game on a ipad and when i swipe down the game disappears. it says “in full screen swipe down to exit”

Dragging is not good for swap.
Try with TopDownMovement or Tween behaviors.
And also need to have two points for swap.

2 Likes

So I am left with just clicking?

1 Like

Is that on a browser? That can really be a issue if your game will be released for browsers

1 Like

Yes it is. Bejeweled and Candy Crush would be failures without it.


I’m confused. I’ve given an example of how to do it with dragging behaviour. Did that not work for you?

I use Tween for swap with two points.
If there is no match on 3 there is back to swap.
How to create with drag back to swap?
:smiley:

How do you determine which position to tween to?

Generally, the drop event is used to figure out the target position, then a tween is used to move to the target position (or back to the original position if determined by the game rules).

Note that in this case the tween is just a nice way to animate the object movement. I didn’t include it in my example because that wasn’t the focus of the example.

1 Like

I keep trying everything. I won’t give up. I am watching the online tutorials and reading the documentation.

You mean released on the gdevelop gaming site? Because I just starting learning a couple of months ago, the gdevelop site is the only place that I am serving all my games to.

I like the check for direction with drag (which I tried) then tween to that position. I will try that. Thanks.

I meant, that if your ipad says “in full screen swipe down to exit”, it will be a problem, not only for you but to anyone who uses ipad and tries to play the game in fullscreen.

How do i fix that???

You can’t fix that, that is probably browser-level.

Got the objects to stop at 100 pixels and swap if within the boundaries of the playing board.

I changed the candy match to Valentine’s Day Match.