Jump to content


Photo

Sokoban Puzzles

puzzles variables events

  • Please log in to reply
9 replies to this topic

#1 Koi

Koi

    Advanced Member

  • Members
  • 147 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 08 August 2013 - 07:56 PM

So I'm making a Sokoban puzzle in my game, but I'm not sure how to make it work...

 

Psst this is a Sokoban puzzle:

Sokoban_animation.gif

 

I looked up variables and got a basic idea of how to use them. Basically what I want is for movable rocks to activate a variable when placed on certain tiles, and when all have been correctly placed (4 of them in all), a door will open.

 

Please help?


Icon by me, full pic here.


#2 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 16,408 posts
  • LocationAustralia
  • Primarily UsesN/A

User's Awards

        

Posted 08 August 2013 - 08:30 PM

The easiest way is to just use Region IDs to paint the tiles where the boxes need to go, then have a parallel process event running on that map that does something like this:

Get Location Info (Event 1's region id) into a variable
If variable is not correct region id
  Jump to Label 'fail'
End
Get Location Info (Event 2's region id) into the same variable
If variable is not correct region id
  Jump to Label 'fail'
End
... repeat for each event that represents a box
Get Location Info (last event's region id) into the same variable
If variable is not correct region id
  Jump to Label 'fail'
End
# By this stage, all box events are on the correct tiles
# do winning stuff
Set Self Switch A on (controls next page on same event, which stops the parallel process from repeating)
Label 'fail'
Wait 5 frames (so there's no lag)
That way your events just have to worry about moving, and your 'success' check is entirely independent.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#3 Koi

Koi

    Advanced Member

  • Members
  • 147 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 08 August 2013 - 08:36 PM

The easiest way is to just use Region IDs to paint the tiles where the boxes need to go, then have a parallel process event running on that map that does something like this:
 

Get Location Info (Event 1's region id) into a variable
If variable is not correct region id
  Jump to Label 'fail'
End
Get Location Info (Event 2's region id) into the same variable
If variable is not correct region id
  Jump to Label 'fail'
End
... repeat for each event that represents a box
Get Location Info (last event's region id) into the same variable
If variable is not correct region id
  Jump to Label 'fail'
End
# By this stage, all box events are on the correct tiles
# do winning stuff
Set Self Switch A on (controls next page on same event, which stops the parallel process from repeating)
Label 'fail'
Wait 5 frames (so there's no lag)
That way your events just have to worry about moving, and your 'success' check is entirely independent.

 

 

I can't read RGSS3, and I have no idea what Region IDs are. You'll have to forgive me, this is my first time working in RPG Maker.


Icon by me, full pic here.


#4 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 16,408 posts
  • LocationAustralia
  • Primarily UsesN/A

User's Awards

        

Posted 08 August 2013 - 08:40 PM

That is not RGSS3. It's just pseudocode - you can do it all with event commands.
- Get Location Info
- Conditional Branch (variable)
- Jump to Label
- Label

In your editor, there's an icon to do map editing, an icon to edit events, and the next icon is to edit the regions. Hit that, choose a single region from the palette, and click on all the destination tiles with it. Then you can use Get Location Info to get the region id of an event, and see if the event is on one of those tiles.


Oh wait - there's a mistake there. I thought you could select events and get the region id. You can't - it requires coordinates. So prior to each Get Location Info, you'd have to do a Change Variables to get each event's X and Y value, and use the variables in the Get Location Info to retrieve the region id.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#5 Koi

Koi

    Advanced Member

  • Members
  • 147 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 08 August 2013 - 08:48 PM

Oooh I see...

 

I'm still really confused. I best learn through being provided examples, if that's not too much trouble. I need to know what event commands to put on the tiles, the movable events, and for the door.


Icon by me, full pic here.


#6 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 16,408 posts
  • LocationAustralia
  • Primarily UsesN/A

User's Awards

        

Posted 08 August 2013 - 08:57 PM

Yeah, I'm just doing it up now. And I realize you don't even need to use regions - if you're not using them for anything else, you can just assign a unique terrain tag to the map tile that you use for 'destinations', and poll that instead.

I'll post some screenshots in a couple of minutes (after I confirm that it's actually working properly).

Do you mind if I do this up as a tutorial and share with the community?
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#7 Koi

Koi

    Advanced Member

  • Members
  • 147 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 08 August 2013 - 09:03 PM

Yeah, I'm just doing it up now. And I realize you don't even need to use regions - if you're not using them for anything else, you can just assign a unique terrain tag to the map tile that you use for 'destinations', and poll that instead.

I'll post some screenshots in a couple of minutes (after I confirm that it's actually working properly).

Do you mind if I do this up as a tutorial and share with the community?

 

That's a great idea! I'm sure more people would want to know how to make a puzzle like that for their game.


Icon by me, full pic here.


#8 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 16,408 posts
  • LocationAustralia
  • Primarily UsesN/A

User's Awards

        

Posted 08 August 2013 - 09:09 PM

Ah well, I'm going through the steps and posting images for you anyway, so I may as well put it over in tutorials instead of a support thread :)

I'll update here when it's done.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#9 voymasa

voymasa

    Advanced Member

  • Members
  • 116 posts
  • Primarily UsesRMVX Ace
  • First LanguageEnglish

Posted 08 August 2013 - 09:49 PM

Shaz, would it be possible to simply set up X number of parallel process events that check to see if they are occupied by said object (i.e. the boulder) and while they are increment a single shared variable that when it equals the number of boulders (using a constant for that puzzle) it would run the puzzle solved event?

ex.

 - There are 4 boulders in the room and 4 "hotspots" to place them.

 - Each "hotspot" is an event that checks to see if the boulder is above them (as a parallel process)

   - If the "hotspot" is occupied, then increment the 'puzzlevariable' by 1.

   - Else, wait a few frames and try again.

 - When 'puzzlevariable' reaches 4, the door opens, or a chest unlock SE plays (you could even allow it to temporarily increment by 1 when the player steps on the 'hotspot', especially if it's a floor switch).

 - In the case of the player stepping on the last 'hotspot' to "complete" the puzzle, you could have the 'hotspot' decrement the variable every time it finds that nothing is on top of it (thus playing the unlock/open SE when the player steps on it, but then playing a close/lock SE when they step off, requiring them the use the boulders/boxes).

 

I hope my explanation is clear. 1 variable, 4 moveable objects (boulders/crates), 4 hotspots/switches


Edited by voymasa, 08 August 2013 - 09:50 PM.


#10 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 16,408 posts
  • LocationAustralia
  • Primarily UsesN/A

User's Awards

        

Posted 08 August 2013 - 10:05 PM

It would be possible, but not efficient. You'd have multiple parallel process events all running at the same time (=bad), and each one would have to compare its own position with that of every boulder event - not just ONE boulder event, because you could put any boulder on any hotspot. And you'd have to also check for a boulder being moved OFF a hotspot, as well as stop the parallel process event CONTINUING to increment the variable because the boulder stays on it. You would also need more than 1 variable - one for the counter of boulders correctly placed, and one for the X and Y location of the boulder and the X and Y location of the hotspot, for EACH boulder and hotspot (since they're running in parallel, you don't want to risk one event changing the variable while another one is still in the process of checking its value).

Could do it that way, but it'd be very messy.

My tutorial will take the approach I've described above (using only one event for each object, plus one additional event to test their positions), but it's certainly not the only approach you could take.


Here you go - tutorial complete.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com





Also tagged with one or more of these keywords: puzzles, variables, events

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users