How To Use The Action Command – PuzzleScript

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.

The Action Command

By now we know how to walk around, push blocks and pull blocks, but what if we wanted something to only occur when we press a specific key like spacebar?

PuzzleScript is a bit limited in what it allows for input, mainly being the arrow keys, Z for Undo, R for Restart, and we can’t change those, but it does also give us an extra key for Actions – either pressing spacebar or the key.

Using the Action command follows a similar format to before. We’re used to the basic format of PuzzleScript coding:

[ Condition ] -> [ Event ]

If the condition is true, we do the event. We use the action command the same way, but it has it’s own rules. It looks like this:

[ Action Extra Conditions ] -> [ Event ]

An example of using the Action command would be this:

[ Action Player ] -> [ Crate ]

First, Action is always the first word you must put in the condition.

Second, if you want to affect a specific object in the game, you must mention that object in both the condition and the event ( if you mention a different object, it will delete the original and replace it, or mentioning no object will simply remove it).

Finally, you only have to mention the word Action in the Condition, however, there are times you might want to mention it in the condition and the event, which I’ll go into.

Try the above code in a game project. You can start with this sample one. You will see that what happens is, when you press spacebar or x, the player object becomes a crate.

The condition is saying, [ If you press the Action key and if there is a Player object in the level ] -> then [ replace the player object with a crate ]

Now in your sample project, try the following code:

[ Action Player | Crate ] -> [ Player | > Crate ]

Action Btn 2

Make sure you’re surrounded by crates as in the above image. You’ll notice that it only affects one crate at a time. I’m not sure what the reason is, but if you want to affect multiple objects with the Action command, you need to put it in both the condition and the event.

Replace the code with this updated version:

[ Action Player | Crate ] -> [ Action Player | > Crate ]

Action Btn 1

Now you’ll see that  you push all of the crates at once. If you need to apply the action to multiple objects, make sure you put Action in both the condition and the event.

Conclusion

The next tutorial is on How To Check For Multiple Conditions.

Follow this blog for more tutorials on Puzzle Script, games development and updates on my projects.

Next Tutorial >

 

 

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s