I have about 20 tiles inside a group. The tiles are at random positions. I want to save the position of each clicked tile into different variables. I tried:
For each instance of Tiles
The cursor/touch is on Tiles
Left button of mouse was released
Change the sceneVariable posx1 set to Tiles.X()
Change the sceneVariable posy1 set to Tiles.Y()
Of course, it doesn’t work.
Any help on that please?
You don’t need for each.
Mouse is on tile will specify your tile.
I think you need to change scene variable to object variable,
Change Tilewhatever.Variable(var_X) = Tilewhateve.X()
Change Tilewhatever.Variable(var_Y) = Tilewahtever.Y()
Otherwise you always get the last tile x/y because is only one variable that you’re changing.
if you want to save the pos of all tiles (on exit/scene change ect) save ther positions into a structure.
look up the level editor example.
I’m trying to do what you said, but it’s not working, but I wont give it up.
Actually, I used 4 scene variables x1,y1 and x2,y2. In my post I didn’t write down my full code. But it didn’t work.
I tried to use Object Variable too, but no success.
It keeping saving only last click.
I want to save first and second positions to switch the tiles positions when I click the second.
Give each of your tiles an object variable (name) to identify which tile it is.
Whatever your save condition is, put as subevent of it:
Set variable (counter) to 1
Repeat for each tile
→ set variable(Save[variableString(counter)].name to tile.variable(name)
set variable(Save[variableString(counter)].x to tile.X()
set variable(Save[variableString(counter)].y to tile.Y ()
Add 1 to variable (counter)
To place your tile with the structure you do
Condition to load tiles
Set variable(counter) to variableChildCount(save)
Repeat variableChildCount(save) times
→ among objects tiles named variableString (save [variableString (counter)].name) at position (save [variableString (counter)].x) / (save [variableString (counter)].y)
Subtract 1 from variable( counter)
Damn, this is annoying to type on phone
lol! No matter how hard is to type on phone, it’s easier than understand the logic of your code, but I’m gonna try it. Thanks for while! Pray for me!
Why do I have to use this:
" → among objects tiles named variableString (save [variableString (counter)].name) at position (save [variableString (counter)].x) / (save [variableString (counter)].y)
Isn’t this used to create an object?
I don’t need to create my objects. They’re already on scene. All I need is switch their positions.
I never wrote you have to. I showed how you can use your structure to load your tiles.
why do you want to save the positions?
I was assuming to load them later.
No! As I said, I want to switch their positions.
To switch positions you don’t need any variables
Describe what you want to do exacly
I want to click on first tile, then when I click on the second I want they switch their positions.
I need to save positions, to make the tiles know the positions they should go after second click.
Well, this can be done in variables, yes.
I’ll go on the pc to make events and share a screenshot
I appreciate your help! And I’m glad to know you are on pc, so you don’t have to use your phone to type!
wow! I did exactly what you did. My mistake was not setting the change actions as a sub event, so when I was adding 1 to the object variable on top, the code was reading only the second actions because the object variable had already added 1.
I need to pay more attention.
Many Thanks Slash! For your time and kindness!
Have an excellent day and a great weekend!