Sometimes you want to check more than one condition. It’s quite a common programming technique in engines like Unity where you have to code everything, which I did in Puzzledorf for situations like below:
In Puzzledorf, I had to code things in Unity so that when you try and push a block, it checks if there’s anything on the other side, and what it is, to stop people pushing 2 blocks at a time or pushing a block through a wall. Thankfully Puzzlescript handles these sorts of basic collisions for you. But what if you wanted to check something else in Puzzlescript, like is there a bomb on the stage AND a destructible block?
This tutorial will teach you how to do that by checking multiple conditions. It assumes no prior programming knowledge except the previous Puzzle Script tutorials I have written.
Checking For Multiple Conditions
Open the sample project. Now add this code to your project:
late [Player Switch][DoorClosed] -> [Player Switch][DoorOpen]
The code follows this format:
[ Condition 1 ] [ Condition 2 ] -> [ Action 1 ] [ Action 2 ]
If condition 1 is true, and condition 2 is true, then do action 1 and action 2. In this case, condition 1 is checking if the Player is on a Switch. If he is, then condition 2 is checked, which is, is there a closed door anywhere in the level? If the check is true, then the DoorClosed object becomes a DoorOpen object, opening the door.
Say we want the door to close when the hero steps off the switch though, because we want the player to push a crate onto the switch to keep it open. You can write something like this:
late [Player | Switch][DoorOpen] -> [Player | Switch][DoorClosed]
If the player is standing next to a switch, and there is an open door anywhere in the stage, close the door. Finally, we want to keep the door open if we push a crate onto the switch:
late [Crate Switch][DoorClosed] -> [Crate Switch][DoorOpen]
Now the door will stay open when there is a crate on the switch.