Trying to swap instances

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.

3 Likes

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

To understand what is going on, when I have issues, I use a lot the “Log a message to the console” function to write some usefull info in the console. For example, which value take these variables when the swapping should occur.

By the way, is it possible that your purple candy collides with 2 bleu candies ? If so, the 2 bleu candies would probably overlap each other.

1 Like

when I swipe the purple candy over the purple up and down stripped candy this is the results.

Here’s the code. The test textboxes show the StartX and StartY results and the SwitchX and SwitchY results. After this switch all matches are found and replaced with random instances of candies. It should work. I am obviously not seeing what is going wrong.

Then when I hold down the cursor/touch on purplecandy, it tries to swap with a bunch of other instances???

Maybe this game is not possible?

I wish there was a more formal way of learning the gdevelop editor. So far I have been cruising the internet for solutions and on this community forum. A bit frustrating. But it is a nice change from hard coding.

The suggestion of deactivating the drag behavior. I will try it.

I think it’s a good idea not to go with draggable behavior. For one thing there will be less complexity in making sure your players don’t drag candy to inappropriate places all over the game screen. They are really only going 1 block over. They don’t need to actually have to pick up a piece of candy and physically carry it to the box they want it in. It’s right there.

I’m working on a project that involves swapping places too and at this stage I think changing positions with a simple tween would be better, unless I decide to go with a multi animation single object later. But since I am using different game objects for each swappable item right now I think our swapping is similar so far. But I put all my swappable items in a group and just call the group instead of the individual swappable items. I use the Swipe Gesture extension to detect when swipes end. I also use the Pinch Gesturing extension as a simple and lazy way to tell when the player has more than one touch on the screen so I can prevent swaps from happening then (prevents the incorrect object picking that can occur with multiple touches). I make positioning blocks so I know what pieces to swap and where.

Here are the events I’m using so far. Just ignore the notes, I don’t get a lot of time to work on my projects so I like to keep notes so I don’t spend all my time wondering what I was doing or why on earth I’m doing it this way and not that way. So hopefully you can find some inspiration or ideas.

Summary

This is just a placement image so you can better see where the 3 main event groups are.

This main event group is selecting the piece to swap

This one is selecting where to swap it (using swipe)

And this is just some extra utility where I delete all blocks and center if there is more than 1 touch on screen, and also delete blocks immediately after creation if they are not on the game board, so the player can not swipe pieces off the board

1 Like

Wow wee comforting to know that there are other game developers out there willing to help me out. Games are a great way to keep people on your website. I would love to make games to put on company websites.

I took a quick look at your code but it is late at night so I will have to take a closer look tomorrow.

Thanks for the input.

1 Like

Well, I don’t even know if it will help. It’s just swapping positions, I haven’t created the rules for detecting if a swap is valid or not. But it might give you some ideas anyway.

1 Like

I tried the cursor/touch is on event instead of dragging the instances. It kind of works…but it has the same troubles as the dragging code, it leave a blank space sometimes…and you can drag the instance all over the screen.

I’ll try something else.

Going to try a suggestion from Drona. How do i change an object into another object? - #2 by Drona

The easiest way to do that would be to store the coordinates of object A, delete it and create object B at the stored position of object A.

Another way would be to have different animations (with your object A and B) for the same sprite and change the animation you need in the events.

Tried the delete/create thingy. Still not working.

Do your candy objects have draggable behavior? I can’t think of anything else that would let them drag all over the screen.

If I delete this behavior I can not drag the instances.