Creating Custom Movement
For some reason you might want to create custom movement in your game. Ducks that can only walk left, crates that can only be pushed horizontally, that sort of thing. There’s a very simple way to do that. Let’s review the base PuzzleScript code format again:
[ Condition ] -> [ Event ]
If the condition is true, the event happens. To create custom movement, we do this:
[ Condition ] -> [ Movement Direction Object To Move]
This is what an example would look like:
[ Player | Crate ] -> [ Player | Left Crate ]
If you load up PuzzleScript and open the Basic example, put that code in and see what happens. Make sure you walk up to a crate that has no walls around it.
You’ll see that the crate gets pushed left when the player is next to it – though because it is not on Late, it will get moved on the turn after when you first step next to it.
When you specify a Movement Direction such as Left beside an object in the Event of PuzzleScript code, it will attempt to move that object in the specified direction. That is why the crate moves left, and not the Player, because Left is beside Crate.
Remember this from the previous tutorial?
[ Movement Direction Object Affected ] -> [ New State of Object ]
When you place a Movement Direction in the Condition beside an object, it checks to see if that object is moving in that direction. It’s an important difference. It could be rewritten as:
[ Check for this ] -> [ Do this ]
Custom Movements You Can Use
You can create custom movements with any of these words:
You can’t use Horizontal or Vertical because PuzzleScript doesn’t understand which direction you want it to move – or to do so would require a lot of work arounds. You need to be specific.
If you have any questions you can leave a comment below. The next tutorial is on how to check next to objects.
Follow this blog for more tutorials on Puzzle Script, games development and updates on my projects.