Tutorial-Blog Eventing a Push/Pull System
Official Content Discussion ThreadsThat's a pretty good way of donig it! When I did boulder puzzles in my 2000/2003 projects they only had a simple push mechanic and I remember just telling the player to exit and reenter the scene if they got stuck.
I've always included a reset button of some sort even with push only puzzles.
The method that @hiddenone used to do the pulling though is pretty spiffy. Definitely will be yoinking it myself in the future.
Having to reset puzzles over and over while testing is why I came up with the pulling part. 😅 After rolling a rock against a wall one too many times, I decided it would just be easier if I figured out a way to let players fix any mistakes they made without having to reset the entire puzzle.
This blog post was super helpful as a guideline. I would have had no idea how to even begin implementing a push/pull system if it wasn't for this. Thank you so much!
I used this post as a basis for understanding how a push/pull system should work but took out the scripting and used if/else clauses exclusively just because it was easier for me to wrap my head around.
I also had no need for any of the direction fix calls so I left that out. For anybody else who struggles with scripts, this is also a functional option.
I used this post as a basis for understanding how a push/pull system should work but took out the scripting and used if/else clauses exclusively just because it was easier for me to wrap my head around.
I also had no need for any of the direction fix calls so I left that out. For anybody else who struggles with scripts, this is also a functional option.
I wonder if I can make moving platforms w/ this method...
Pushing works very well, I have a problem with pulling
the player moves, not the event.
the player moves, not the event.
@ulosbal: I think the player is in the way. Move routes process 1 command per frame: the player's route has 2 commands before they move, so the event should wait 2 frames before its move, not 1.
Thanks @caethyril that did not solve my problem ... :/
But by adding a few frames at the start of the loop
prevents the player from sliding when you press the arrows before the space bar.
(it was another problem I had)
But by adding a few frames at the start of the loop
prevents the player from sliding when you press the arrows before the space bar.
(it was another problem I had)
@ulosbal Caethyril was right about adding extra wait frames, but for some reason the 'change image' option needs a little longer than 1 frame. So instead of waiting 2 frames, try 3 and see if that works (it did in my quick test, so hopefully it will for you). 🙂
@hiddenone Yes I have already tried different number of frames until I have too many! nothing works.
I am so close to the goal ...
edit: to solve my problem I did this:
I am so close to the goal ...
edit: to solve my problem I did this:
I tried to recreate this push/pull system, and as far as I can tell, mine is *exactly* the same as what's shown here. Pushing works fine but pulling crashes the game though.
Would be great if someone could tell me what's wrong since I'm obviously missing something.
I'm using variable 4 instead of variable 11 but besides that, I can't find any differences?
Would be great if someone could tell me what's wrong since I'm obviously missing something.
Code:
◆Comment:Prep the player for moving
◆Set Movement Route:Player (Wait)
: :◇Direction Fix ON
: :◇Speed:3
◆Wait:3 frames
◆Loop
◆Comment:These conditional branches check if the player is pressing the same
: :arrow key as they are facing, which will make the player push the block.
◆If:Player is facing Down
◆If:Button [Down] is pressed down
◆Control Variables:#0004 Pushing or Pulling = 1
◆
:End
◆
:End
◆If:Player is facing Left
◆If:Button [Left] is pressed down
◆Control Variables:#0004 Pushing or Pulling = 1
◆
:End
◆
:End
◆If:Player is facing Right
◆If:Button [Right] is pressed down
◆Control Variables:#0004 Pushing or Pulling = 1
◆
:End
◆
:End
◆If:Player is facing Up
◆If:Button [Up] is pressed down
◆Control Variables:#0004 Pushing or Pulling = 1
◆
:End
◆
:End
◆Comment:This Script Call checks if the player is pushing the opposite arrow
: :key as they are facing, which will make the player pull the block.
◆Script: if (
: :($gamePlayer.direction() == 2 && Input.isPressed("up")) ||
: :($gamePlayer.direction() == 8 && Input.isPressed("down")) ||
: :($gamePlayer.direction() == 4 && Input.isPressed("right")) ||
: :($gamePlayer.direction() == 6 && Input.isPressed("left"))
: :) {
: :$gameVariable.setValue(4, 2);
: :}
◆Comment:The actual movement of the event and player.
◆If:Pushing or Pulling = 1
◆Comment:Pushing movement.
◆Set Movement Route:This Event (Skip)
: :◇Move away from Player
◆Set Movement Route:Player (Skip, Wait)
: :◇Wait:1 frame
: :◇1 Step Forward
◆
:End
◆If:Pushing or Pulling = 2
◆Comment:Pulling movement.
◆Set Movement Route:Player (Skip)
: :◇1 Step Backward
◆Set Movement Route:This Event (Skip, Wait)
: :◇Wait:1 frame
: :◇Move toward Player
◆
:End
◆Comment:Check if 'ok' is still being held down. If not,
: :then the action will end.
◆If:Button [OK] is pressed down
◆
:Else
◆Break Loop
◆
:End
◆Comment:Make variable 0 again, so that the player won't keep pushing/pulling
: :if the arrow keys are not being touched.
◆Control Variables:#0004 Pushing or Pulling = 0
◆Wait:1 frame
◆
:Repeat Above
◆Comment:Reset player to their normal form
◆Set Movement Route:Player (Wait)
: :◇Direction Fix OFF
: :◇Speed:4
◆Comment:Reset variable to 0.
◆Control Variables:#0004 Pushing or Pulling = 0
And here is the error msg:I'm using variable 4 instead of variable 11 but besides that, I can't find any differences?
@Parallax Panda: in your script call you've written
Alternatively, you could remove the script call and add "pull" checks alongside the "push" checks, e.g.
$gameVariable, but it's supposed to be $gameVariables (plural variables).Alternatively, you could remove the script call and add "pull" checks alongside the "push" checks, e.g.
Code:
◆If:Player is facing Down
◆If:Button [Down] is pressed down
◆Control Variables:#0001 Pushing or Pulling = 1
◆
:End
◆If:Button [Up] is pressed down
◆Control Variables:#0001 Pushing or Pulling = 2
◆
:End
◆
:End
@caethyril
Magnificent!
Now it works as it's supposed to, thank you. I read and compared the snippet several times yet I didn't catch it. It's so easy to stare yourself blind to small stuff like that.
Magnificent!
Now it works as it's supposed to, thank you. I read and compared the snippet several times yet I didn't catch it. It's so easy to stare yourself blind to small stuff like that.
@Parallax Panda I'm glad caethyril was able to point out what was wrong, missing 's's is where I often stumble too. 😅
Don't feel like you have to use the script calls, since using the script calls isn't really necessary to get the event working. It's why I showed how to use event commands as well. Either option would work and the only difference is which way of eventing you're more comfortable with. 🙂
Don't feel like you have to use the script calls, since using the script calls isn't really necessary to get the event working. It's why I showed how to use event commands as well. Either option would work and the only difference is which way of eventing you're more comfortable with. 🙂
Really great guide. Thanks for making it.
I've found an odd quirk where the player will sometimes (not always, go figure) push the block at double speed. This affects the speed of the object and the player. Can't for the life of me work out where its going wrong.
This even occurs if I don't return the player speed back to normal.
I even tried using the script instead of the conditional branches and it is exactly the same. Only occurs on push, never on pull.
Update: This is caused by the fast forward function inside MZ.
To disable use this script (thanks to Aesica and Niniann):
I've found an odd quirk where the player will sometimes (not always, go figure) push the block at double speed. This affects the speed of the object and the player. Can't for the life of me work out where its going wrong.
This even occurs if I don't return the player speed back to normal.
I even tried using the script instead of the conditional branches and it is exactly the same. Only occurs on push, never on pull.
Update: This is caused by the fast forward function inside MZ.
To disable use this script (thanks to Aesica and Niniann):
Scene_Map.prototype.isFastForward = function(){ return false;
Window_BattleLog.prototype.isFastForward = function(){ return false; };
Great tutorial. I was playing with this and trying to get a Sound Effect to play when the block was moved.
I came up with this for Pushing:
And this for a Pull:
Those two will get you a Sound Effect to play when you move the object, but only if it is actually moved.
I also Gather Followers and Change Player Followers: OFF before hand and call this after I Change Player Followers: ON:
That will stack all of the followers on the Player after you're done and prevent them from running through your block.
I came up with this for Pushing:
JavaScript:
// Get Player Facing and 0 X & Y
var direction = $gamePlayer.direction();
var targetX = 0;
var targetY = 0;
// Create Block Coordinates based on Player Facing
switch(direction) {
case 2:
targetY = 1;
break;
case 4:
targetX = -1;
break;
case 8:
targetY = -1;
break;
case 6:
targetX = 1;
break;
default:
targetX = 0;
targetY = 0;
break;
}
// Compile X & Y
var finalX = $gamePlayer.x + targetX;
var finalY = $gamePlayer.y + targetY;
// Play SE if Block is Movable
if ($gamePlayer.canPass(finalX, finalY, direction)) {
AudioManager.playSe({name: 'Earth5', pan: 0, pitch: 120, volume: 40});
}
And this for a Pull:
JavaScript:
// Check Player Facing and zero Event Direction
var direction = $gamePlayer.direction();
var eventDirection = 0;
// Set Facing in Opposite Direction
switch(direction) {
case 2:
eventDirection = 8;
break;
case 4:
eventDirection = 6;
break;
case 8:
eventDirection = 2;
break;
case 6:
eventDirection = 4;
break;
default:
eventDirection = 0;
break;
}
// Play SE if Block can Move
if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, eventDirection)) {
AudioManager.playSe({name: 'Earth5', pan: 0, pitch: 120, volume: 40});
}
Those two will get you a Sound Effect to play when you move the object, but only if it is actually moved.
I also Gather Followers and Change Player Followers: OFF before hand and call this after I Change Player Followers: ON:
JavaScript:
$gamePlayer._followers.synchronize($gamePlayer._x, $gamePlayer._y, $gamePlayer._direction);
Original thread: https://forums.rpgmakerweb.com/threads/eventing-a-push-pull-system.129220/