How To Limit Movement To Specific Directions – PuzzleScript

Join the Discord. Talk about Game Dev. Talk about Gaming.

This post is part of a series in learning how to make games with PuzzleScript. If you haven’t read my previous tutorials, I recommend you do so here, as that is assumed knowledge for this post.

Creating Limited Directional Movement

For some reason you might want to limit which directions an object can move in. Ducks that can only walk backwards, crates that can only be pushed horizontally, that sort of thing. There’s a very simple way to do that. I experimented with this idea for Puzzledorf but abandoned it for that particular game (although you may see it in a sequel…); it has merit for certain games, though.

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:

  • Up
  • Down
  • Left
  • Right

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.

The next tutorial is on how to check next to objects.

Next Tutorial >

Join the Discord. Talk about Game Dev. Talk about Gaming.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: