How can I make it so a switch opens a door only when something is on top of it?

Discussion in 'RPG Maker MV' started by hero_buddy, Jul 17, 2019.

  1. hero_buddy

    hero_buddy artist and pro cat petter Veteran

    Messages:
    45
    Likes Received:
    67
    Location:
    hawaii
    First Language:
    English
    Primarily Uses:
    RMMV
    i'm making my first dungeon, and want to include a mini puzzle, where the player pushes a boulder on top of a switch to open the door. i'm a bit confused on how to do this though... could anyone help me out? i know how to make the boulder pushable, but everything else, i'm stuck on. :yswt: sorry if i'm posting this to the wrong section.
     
    #1
  2. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    226
    Likes Received:
    764
    First Language:
    English
    Primarily Uses:
    N/A
    You can do it a bunch of ways. Here's one.
    The event for the 'switch' that you roll the boulder on should be set to Through and as a parallel process.
    It's honestly quickest to use script calls, in my opinion.
    It should have a conditional branch, and you should select Script and enter the following
    $gameMap.event(id1).y == $gameMap.event(id2).y && $gameMap.event(id1).x == $gameMap.event(id2).x
    Replace id1 with the id of the 'switch' event
    replace id2 with the id of the boulder event

    Inside of the conditional branch, do whatever you're planning on doing to 'unlock' or open the door. Change the self switch for the Event with the code above to self switch A, and leave the second page alone(with self switch A as it's page condition).

    EDIT:
    I've added pictures from my test
    floorSwitch.png

    And the second event, the boulder that was rolled
    boulderEvent.png

    The floor switch event's id is 1, and the boulder event's id is 2. I copied and pasted the call above, replaced the id's in the parenthesis of the script call to 1 and 2.
    When the boulder rolls on top of the switch, in the test, it simply shows a Text box and then switches it's Self Switch to A. I didn't show a picture, but the second page of the floor switch event is a blank page, with the floor switch as the graphic. Through is still on, and the page condition is Self Switch A.
     
    Last edited: Jul 17, 2019
    #2
  3. TWings

    TWings The Dragon Whisperer Veteran

    Messages:
    305
    Likes Received:
    576
    Location:
    Kyoto
    First Language:
    French
    Primarily Uses:
    RMMV
    Actually if you want your door to be opened only when the boulder's on it (meaning the door closes as soon as the boulder's off it) :
    - You need to use a Switch that will indicate if your door is opened (if ON door opened, if OFF door closed).
    - You need to check at the end of your boulder's movement if it's on your switch event or not (if it's on it, you turn the door Switch ON, else you turn it OFF).
     
    #3
    caethyril likes this.
  4. caethyril

    caethyril ^_^ Veteran

    Messages:
    1,042
    Likes Received:
    648
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Not sure why @standardplayer has used a script in the move route; Move Away From Player works fine? Also I would suggest putting the position check in the boulder's move route, like @TWings implies; there's no need to have the check repeating in the background the whole time. :kaoswt2:

    Also, in case you're interested: you can do the whole position check thing using Control Variables > Game Data > Character > Map X|Y.
    Code:
    ◆Control Variables:#0001 positionCheck = Map X of Boulder
    ◆Control Variables:#0001 positionCheck -= 4
    ◆If:positionCheck = 0
      ◆Control Variables:#0001 positionCheck = Map Y of Boulder
      ◆Control Variables:#0001 positionCheck -= 5
      ◆If:positionCheck = 0
        ◆Comment:In position!
        ◆
      :Else
        ◆Comment:Not in position.
        ◆
      :End
      ◆
    :Else
      ◆Comment:Not in position.
      ◆
    :End
    This example compares the boulder's position against x=4, y=5; it just checks the difference between the boulder's coordinates and the target position. Then you can toggle your switch on/off (and play SE, animate your door, or whatever) where appropriate. Note that you can link the two "not in position" parts with Label & Jump To Label commands if you like, to avoid eventing the same thing twice~ :kaothx:

    You can do the position check any time 1 frame after the boulder's movement starts. A typical approach is to set the boulder's move route to "Skip if Cannot Move" and "Wait for Completion" (checkboxes below the move list), then do the check immediately afterwards.
     
    #4
    TWings likes this.
  5. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    226
    Likes Received:
    764
    First Language:
    English
    Primarily Uses:
    N/A
    @hero_buddy of course, my solution involves what I typed, not arbitrary things that were simply force of habit and part of a quick test.
    The pictures came after I wrote 'EDIT', just to show that I tested my solution. So using a script call for move route was a preference and a habit. I do a lot of things through script, for various reasons. However, since I didn't type anything about it in my solution, you shouldn't consider it a necessary part.

    Yes, you could have the boulder doing the position check, but ultimately having it on the switch would make it easier to add something like open the door if you (the player) stood on the switch.
    Since you didn't say you wanted that to happen, my solution simply has the second page of the floor switch event as blank. However, if you planned on adding in handling for what to if the boulder was rolled off of the switch, that would be the place for it to happen. Yes, you could do it all on one page, but pages aren't just there to make events behave differently. They can help organize, and make troubleshooting less of a hassle.
    Also, if you wanted to handle the player stepping on the switch, you couldn't reasonably handle that on the boulder event.

    Altogether, I just saw more potential in putting that as a parallel process on the floor switch, because it allows for more flexibility in the end, and I'd hate to give you a solution that would be a pain to alter.

    Solutions often turn into more ideas, and it's a good practice to make events as flexible as you can. You may want to alter them later or use them as templates for similar processes on other maps.
    A good setup is good practice.
     
    Last edited: Jul 17, 2019
    #5
  6. Frogboy

    Frogboy I'm not weak to fire Veteran

    Messages:
    1,670
    Likes Received:
    2,060
    Location:
    North Carolina, U.S.
    First Language:
    English
    Primarily Uses:
    RMMV
    I made a game called Heir to the Kingdom. It's a small puzzle game where you usually split your party up into individual members in order to complete each room's puzzle to get to the next one. It has a similar puzzle where different players have to stand on different switches to unlock the door. That makes it a little different but probably close enough for what you need. The project source is available for download for you to checkout and get ideas from if you want.
     
    #6

Share This Page