Zelda moving blocks

Hi. I need some help for how to event a moving block in the style of Zelda. Note that this is not the same as a rock or something you can push around repeatedly, I'm speaking about the square tiles like in Link to the Past where once you push into it it will only move one tile and cannot be moved again until you leave the screen (where it resets to its original position).


The way I have it set up is


>Play sound
>Move away from player
>Wait 24 frames
>Turn on switch


Then on page 2 it won't do anything. The switches will turn off when you exit the room.


At first glance this does exactly what I want it to do; however, if I was to push the block into a wall or another tile where it won't move, it will still play the sound and turn on the switch as if it moved one tile.


What would be the easiest way for the program to figure out if the block moved one tile or not before deciding to play the sound and turn on the switch? I don't want the event to trigger if the block cannot be moved. Note that this will also be something that will be occurring a lot (often on one screen) so it would be preferable if the solution was as simple as possible.
Post a screenshot of the event for more detailed help, but from the sound of it you have allowed the moveroute to skip the move.


And to check if the block moved or not you can simply use control variable to read the current position (after the move) and determine if those coordinates are the starting position or not with a conditional branch
If you're going to use this event a lot, you may want to consider putting it in a common event.  That way, you can quickly attack it to the object without having to alter the code in every event in the game if a change needs to be made.


Also, did you test out the leaving room mechanic yet?  Because unless I'm mistaken, you may end up using a lot of switches to make this work.  And I'm not sure if you can use


self switches for this, since you can't switch them back off from a different event.  But that's not your question...


The best way to prevent the sound and switch from triggering this way is to encase your code in a conditional branch.  But before the branch, you need to check a variable, which gets a little tricky.  I tried something like this once with a mechanic that summons a boat on the tile in front of you if that tile is water, and what I did was use a few different variables to set up the one it had to check.


First, use 2 variables to check your X and Y location (they need to be separate).  Next, use four conditional branches to check the direction the player is facing, one that checks each direction.  Shift the X or Y variable 2 in that direction.  If you're facing left, for instance, the X variable should be subtracted by 2.  Now the X and Y variables should be on the tile you need to check.  Using those variables as X and Y, check the terrain tag for that tile and put it in a third variable (under Get Location Info; you'll probably need to change the terrain tag in the tileset database manually in the floor you're using)  If the terrain tag matches the one you set, the event should play.  But if the terrain tag says you're going into a wall, it won't do anything.  It's a tricky bit of code, but that's one way to do it.


If you're comfortable scripting, however, get the variables for X and Y and try this script for the conditional:


$gamePlayer.isPassable(x, y, direction)


X and Y should be replaced with


$gameVariables.value(x) (X is the id of the variable of the X coordinate)


Direction may go by the arrows on the keypad on the right, but I'm not sure.  It may just be the words.  I can't be certain if this will work, but you can try it if you want.
Post a screenshot of the event for more detailed help, but from the sound of it you have allowed the moveroute to skip the move.


And to check if the block moved or not you can simply use control variable to read the current position (after the move) and determine if those coordinates are the starting position or not with a conditional branch



It doesn't get any more complicated than what I explained so I'm not sure why a screenshot would be necessary in this case. If you mean you want a reference to what I'm talking about, here is an example: 










Edit: Sorry, forgot to address the second part of your post. In previous games when I'd want to check the position of something (like moving a block on to a switch) I'd end up having a ton of different variables in parallel processes checking the X and Y positions of the player/events in the room and it got really messy and was a pain to deal with. Recently I fixed all of my problems using script conditions, but I'm new to javascript. Instead of having a giant block of code checking variables, I used script conditions like these (as an example):


Check to see if the player (or another event) is standing on top of this event


$gamePlayer.x === $gameMap.event(4).x && $gamePlayer.y === $gameMap.event(4).y


Check to see if the player (or another event) is standing near this event (adjacent 8 tiles)


$gamePlayer.x >= ($gameMap.event(7).x -1) && $gamePlayer.x <= ($gameMap.event(7).x +1) && $gamePlayer.y >= ($gameMap.event(7).y -1) && $gamePlayer.y <= ($gameMap.event(7).y +1)


I'm hoping there's something as simple as that that I can do for this.

If you're going to use this event a lot, you may want to consider putting it in a common event.  That way, you can quickly attack it to the object without having to alter the code in every event in the game if a change needs to be made.


Also, did you test out the leaving room mechanic yet?  Because unless I'm mistaken, you may end up using a lot of switches to make this work.  And I'm not sure if you can use


self switches for this, since you can't switch them back off from a different event.  But that's not your question...


The best way to prevent the sound and switch from triggering this way is to encase your code in a conditional branch.  But before the branch, you need to check a variable, which gets a little tricky.  I tried something like this once with a mechanic that summons a boat on the tile in front of you if that tile is water, and what I did was use a few different variables to set up the one it had to check.


First, use 2 variables to check your X and Y location (they need to be separate).  Next, use four conditional branches to check the direction the player is facing, one that checks each direction.  Shift the X or Y variable 2 in that direction.  If you're facing left, for instance, the X variable should be subtracted by 2.  Now the X and Y variables should be on the tile you need to check.  Using those variables as X and Y, check the terrain tag for that tile and put it in a third variable (under Get Location Info; you'll probably need to change the terrain tag in the tileset database manually in the floor you're using)  If the terrain tag matches the one you set, the event should play.  But if the terrain tag says you're going into a wall, it won't do anything.  It's a tricky bit of code, but that's one way to do it.


If you're comfortable scripting, however, get the variables for X and Y and try this script for the conditional:


$gamePlayer.isPassable(x, y, direction)


X and Y should be replaced with


$gameVariables.value(x) (X is the id of the variable of the X coordinate)


Direction may go by the arrows on the keypad on the right, but I'm not sure.  It may just be the words.  I can't be certain if this will work, but you can try it if you want.



Thank you for the response. This seems to be a bit hectic for what I'm trying to do as I'd probably have to use a bunch of different variables? If you look at the video I posted above you'd see that there are often many objects in a room that do the same action. Also, I have my terrain tags set up for different scripts.


To answer the mechanic question, I don't believe there'd be an issue. At most I might have like 20 blocks in a room, so that would be 20 different switches. Since the mechanic resets upon exiting the room, I'd call a common event that turns off those 20 switches. I wouldn't have to make a unique switch for every moving block in the game.
It doesn't get any more complicated than what I explained so I'm not sure why a screenshot would be necessary in this case. If you mean you want a reference to what I'm talking about, here is an example: 


Edit: Sorry, forgot to address the second part of your post. In previous games when I'd want to check the position of something (like moving a block on to a switch) I'd end up having a ton of different variables in parallel processes checking the X and Y positions of the player/events in the room and it got really messy and was a pain to deal with. Recently I fixed all of my problems using script conditions, but I'm new to javascript. Instead of having a giant block of code checking variables, I used script conditions like these (as an example):

NOT a video of Zelda - a screenshot of the event page inside the RPG-Maker-Editor, so that we can see which commands you have used there.


And you don't need a single parallel process to check for the position - you should have done that in the same (action-button-triggered) event that moves the block.


That way it can't get messy and don't need a single script line at all.
NOT a video of Zelda - a screenshot of the event page inside the RPG-Maker-Editor, so that we can see which commands you have used there.


And you don't need a single parallel process to check for the position - you should have done that in the same (action-button-triggered) event that moves the block.


That way it can't get messy and don't need a single script line at all.



Edit: I spent so much time focusing on the idea of checking the surrounding environment and I could have just simply did a check after moving. I attached the new screenshot with the code that seems to work fine. Might be an even tidier way of doing it but it doesn't matter much now since it seems to be doing exactly what I wanted it to do.

zzzz2.png

Original thread: https://forums.rpgmakerweb.com/threads/zelda-moving-blocks.60354/