Variable expression

I do the same thing. I’m no programming expert but I’ve used a few. Mostly this and Visual Basic. A little JavaScript. All languages have their own interpretation of variables. They’re close but not exactly.

They say that Gdevelop does things like creating variables to prevent fatal errors. I can understand and appreciate it. I do wish it was a little less forgiving during testing. So, you know when you make a typo.

Instances and the way things are picked was a tough concept for me. I still get confused sometimes as to why something isn’t being triggered.

For what you’re doing, you don’t really need an array. A structure is better suited for this purpose. So for the record “add” is only for arrays. It used to be called append. As “append” I’m sure you would think, “Well I can’t append things to a structure! That’s just crazy talk! This action must just be for arrays only…” and you would be right.

So even though the name has changed to “add” to make it seem more inclusive…no it’s not for structures. You don’t need to append things to structures. If you want a new child in a structure you just create it by name.

So you don’t need that line at all. You don’t need to append the text “firstx” to anything because if you want to create a variable inside of selection called “firstx” you can literally just say: if firstx isn’t in selection yet, make firstx in selection and give it the value of tilesX(). Like so:


image

I also put firsty in up above too. Because if firstx doesn’t exist then firsty shouldn’t be there either, or if it is we want to overwrite it with this new value.

So now in this example I want to check if the child “first” is in selection. If not, I want to create the child first as a structure and give it 2 children, x and y. I will do the same for child “second”.


So now I can do things like, change the position of tile set to selection.second.x selection.second.y or whatever.

Here is the action to remove the children
image

But you can also just overwrite the whole structure as Keith hinted to by saying something like: change the value of scene number variable selction set to 8.

For the events snippet and debugger values you placed above, nope. I can’t see any way those events created that variable in the debugger.

Oh! This explanation was so much valuable. I’m starting to understand the concept and how things work. Thanks so much Lucky!

1 Like

It is my fault you got sidetracked to arrays because I thought you wanted an array at first and that’s what I responded to. But honestly in this usage a structure makes more sense to me. Arrays are better when you need the few actions and tricks that you can’t do with structures.

Not your fault at all. I think I didn’t explain it well. But you’re right, structure is what I was trying to do. Thanks you.

I’m just a curious. I used to develop games in AS2, pls don’t laugh!(it was a long time ago), but Flash has been put down and I was not in the mood to restart from zero.
BTW, I replicate your tile game exactly as you did it, but it’s not working. I already checked multiple times and could not find the error yet. Is that event sheet you post above exactly what’s in your game?
Thanks!

I’ve found the glitch! In group “swap tiles” I removed the condition: The number of tile currently picked = 2.

1 Like

Good to hear that it’s working.

I rewrote my project to use an ID variable instead of the position. I try not to use IDs but with a fixed number of objects sometimes it works best. I also added the moves to an array and increases a move counter so, it can be undone all the way to the start. It’s not done. It needs something. It seems like I’m missing something obvious. It needs some more finesse.

try me:

source:

Edit: the effect on the button is black and white So, when the button is disabled it becomes B/W. Buttons really need a disabled state image.

Very good! I’m not using tiled sprite but a group of tiles. And I’m implemeting a rotation on tiles to make the game harder. If you press the Space bar you swap them by clicking, if not tiles rotate 90º.
Thanks for your reply. Hope to see your game ready quite soon.

1 Like

That’s not a game. This is a hobby. That’s an example. I don’t know if I have the discipline or drive to make something bug proof. I enjoy playing with Gdevelop. It’s almost like a puzzle game to me. IDK. But I wish you well.

Oh! no. I’m pretty sure you have!
Same as me. I enjoy a lot trying the resources of GD, especially when my idea works as planned! :slight_smile:
Good luck!

1 Like