Sokoban Puzzle

Hello, I'm trying to make a sokoban puzzle for a game and I got stuck. Below is a screenshot and I'll try to explain what I'm trying to do:
1713191144355.png



Eight rocks, eight sockets for them. I'm trying to achieve the following:

- Once a rock is moved over a socket, it automatically falls into it;
- Any rock can be placed in any socket for it;
- Once a rock has been placed into the socket, the player will be free to stand and move other rocks over it.

How can this be done easily? Or better, how can this be done at all? I found tutorials with variables and setting X and Y positions in VX, but there must be a more efficient way to do it... I don't have much experience setting around variables, I only did it with one rock at a time and then reset it for the player to move it elsewhere. This is becoming more of a puzzle to me than the Sokoban for the player, haha.
you need either 8 or 16 variables or use 2 (to control all 8 rocks)
2 variables are advanced way.

depends how you can push, Galv_PuzzleFunctions make this a bit easier.
as it also have a function for checking X,Y of a position.

do you event the push/pull or use a plugin for that?

the most easiest way is use
rock1 X
rock1 Y

those 2 variables (x and y) counts for all 8.
for the event to check is to check this variable if its on the event location spot.
if it is, flip the page, (which can be a long list) but can be simplified in a complex
and advanced way.

I dont have the time currently, but did something similar with 5 rocks in my case.
which I loop over an array for the condition.
So for the holes. I assume a switch is turned on or something that lets you know the player is holding a rock?

Hole Event (same as player)

Conditional branch.
Is player holding rock?

If yes show choices
1.Place rock into hole
Change variable +1 "Rock holes filled"
self switch A on

2. Leave alone
Else
(Whatever you want for else)

Self switch A page.
Just change the graphic to the filled hole and set it below player.
ShadowDragon:
I am using an event for the push of the rock. So you're saying I should add X and Y variables to each rock and the hole events should be something similar to this?
If Rock1X= ...
If Rock1Y= ...
Control switches: Hole1 = ON

Martin_Arcainess:
There's no switch for figuring out the player is holding a rock, as the player just action buttons them to move away from the player. Else it would be very easy to solve such a puzzle by just taking the rocks and placing them wherever.
yes,

conditional branch: script: $gameVariables.value(1) == 3 && $gameVariables.value(2) == 7
SS A =ON (unable to push/pull)
end

you can continue the list with variables for the rocks or make it advanced

initilize variable array:
gameVariable.setValue(1) = [[3, 7], [4,8], [9, 12]] etc (for all locations)

conditional branch: script: $gamemap.event(ID) === $gameVariables.value(1)[0][1] && $gameVariables.value(1)[0][2]

and do your thing, this also need a list.

but I loop it through an array for the positions, so it auto checks it that way.
You can use @ShadowDragon 's scripting approach, though you can also do it without any variables or scripts and with just one switch if you use RunNearbyEvent.

The basic idea is for the holes to be events, and to trigger those events using the rocks.

Holes
On page 1, have no conditions, just a same-as-player priority and the image of an empty hole.
On page 2, requiring self-switch A, have "though" on, and the image of a filled hole
On page 3, requiring a switch that's always off, have two commands: setting self-switch A on, and a regular switch on (let's call it the "eat a rock" switch). Image doesn't matter, since we'll never see this page, just run it with RunNearbyEvent.

Rocks
I am using an event for the push of the rock
So, I'm assuming the rocks are events with conditional branches that move them depending on the player's direction?
If so, before the code to move them, add a plugin command RunEvent facing 3 - this will run page 3 of the event the rock will move into, if there is one.
After your movement code, check if the "eat a rock" switch is on. If so, hide the rock (e.g. flip a self-switch that activates an empty page) and turn the "eat a rock" switch back off.

Important note: is that this is assuming there are no other events you can push the rocks into (or at least events with a third page).
Hello, going back to this thread because I tried my best to follow advices from here, but I ultimately failed at making it work. I don't really get with RPG Maker MV often, only really have a few hours of tinkering around, so I just need a step by step tutorial on how to make everything work, with all 8 rocks and places for them. Currently what I have is 2 variables for each rock (X and Y positions) individually.
Hello, going back to this thread because I tried my best to follow advices from here, but I ultimately failed at making it work. I don't really get with RPG Maker MV often, only really have a few hours of tinkering around, so I just need a step by step tutorial on how to make everything work, with all 8 rocks and places for them. Currently what I have is 2 variables for each rock (X and Y positions) individually.
I've tried to make my description fairly detailed, and I'm not really sure what else to add to it. Is there some part you didn't understand?
I've tried to make my description fairly detailed, and I'm not really sure what else to add to it. Is there some part you didn't understand?

I'm just very new to all the variable stuff and overall, the game creation process. I did only one game and it almost took me half a year, considering it was very short too, and I have to mix it with my normal life.

I'm sorry for being difficult, but you'll probably have to go very slowly over how to do everything.
You can use @ShadowDragon 's scripting approach, though you can also do it without any variables or scripts and with just one switch if you use RunNearbyEvent.

The basic idea is for the holes to be events, and to trigger those events using the rocks.

Holes
On page 1, have no conditions, just a same-as-player priority and the image of an empty hole.
On page 2, requiring self-switch A, have "though" on, and the image of a filled hole
On page 3, requiring a switch that's always off, have two commands: setting self-switch A on, and a regular switch on (let's call it the "eat a rock" switch). Image doesn't matter, since we'll never see this page, just run it with RunNearbyEvent.

Rocks

So, I'm assuming the rocks are events with conditional branches that move them depending on the player's direction?
If so, before the code to move them, add a plugin command RunEvent facing 3 - this will run page 3 of the event the rock will move into, if there is one.
After your movement code, check if the "eat a rock" switch is on. If so, hide the rock (e.g. flip a self-switch that activates an empty page) and turn the "eat a rock" switch back off.

Important note: is that this is assuming there are no other events you can push the rocks into (or at least events with a third page).
Okay, back into this. I did the holes, although I have a question for them. Does Trigger play any role here, or do I just leave it on Action Button?

For the rocks:

I'm using this. The variables were of an older attempt, before I even asked for help here, so they don't play a role. When the player presses an action button on the rock and there's no wall, the rock will move away from the player.

I thought I could make the 8 holes on the bottom side of the map with a variable that would look on the coordinates and place the rocks, but your approach looks way, way easier. Can you please explain it further, what should I do? I'm lost on this.
1721481325414.png
Well if you not using script, it will be super hard to do. At least you need to solve the problem that player can not walk into a hole but a rock can.
Which means you need to at least detect the hole is in font of the rock. This can be quite a headache if there are multiple holes.

If you are using script this can be very simple.

I used a chest image instead of rock to show the example.
In theory you'll need a page 3(or modify self switch A to have page 2 displayed after the rock stops) after the rock stops moving, which shows the rock inside a hole, and erase the hole itself. But in the example the chest covers the entire hole so I didn't add it.
Spoiler: screenshots
1721486430154.png
1721486580828.png

1721486287923.png
1721486307141.png
Can you please explain it further, what should I do? I'm lost on this.
What do you find unclear in the following instruction from my earlier post?
before the code to move them, add a plugin command RunEvent facing 3
Well if you not using script, it will be super hard to do. At least you need to solve the problem that player can not walk into a hole but a rock can.
Which means you need to at least detect the hole is in font of the rock. This can be quite a headache if there are multiple holes.

If you are using script this can be very simple.

I used a chest image instead of rock to show the example.
In theory you'll need a page 3(or modify self switch A to have page 2 displayed after the rock stops) after the rock stops moving, which shows the rock inside a hole, and erase the hole itself. But in the example the chest covers the entire hole so I didn't add it.

This is awesome, and it seems like it will be working? Would there be a chance for you to deploy this project and send it to me (Windows), so I can play around with it further and also copy the scripts and events themselves?
What do you find unclear in the following instruction from my earlier post?
I'm lost in everything, as I'm not experienced with scripting and plugins in general. I understood parts of what you were trying to say, but I'm only making really tiny baby steps and yeah. I'm really glad you're trying to help, but I'm a lost cause in everything that involves more than just painting the map and setting basic interaction events.
Here is a demo. I also changed some lines so the picture can actually be used.
I also use a fixed route on page 2 to erase the hole.
It seems there's a 1 frame delay when change a self switch, so if you erase the hole and change the chest's self switch at the same time, the image disappear for 1 frame. So I let page 2 do the erase job in its route.
1721529572836.png
Here is a demo. I also changed some lines so the picture can actually be used.
I also use a fixed route on page 2 to erase the hole.
It seems there's a 1 frame delay when change a self switch, so if you erase the hole and change the chest's self switch at the same time, the image disappear for 1 frame. So I let page 2 do the erase job in its route.
View attachment 312033
This is awesome, you're awesome. I still don't really understand what was needed, but thanks to you I have finally solved this after 3 months. Thanks a lot!
You are welcome.
One more question for this approach, is there a way of implementing a check that all rocks are in the holes and then continue from it, and does it involve scripting as well?
Not really, you can add that inside the "If" block, change some variable for example.
if you use a variable +=1 and check this variable === 8 (for 8 spots)
you can do whatever you want after, else nothing happens.

Original thread: https://forums.rpgmakerweb.com/threads/sokoban-puzzle.167767/