Menu Close

Conditionals

The Command Prompt is not just commands. It's commands and conditionals. A conditional is something which has to be true in order for your command(s) to execute. In other words, you can ask Platform Builder something before you run the command(s).

Conditionals are advanced controls that you can use with commands. If you haven’t already learned about commands, please see the Command Prompt page first!

This will look very similar to basic code if you have done that before. If not, it won’t be hard to learn. Let’s look at a few examples:

if money = 100
health + 1 

The above example first checks if the player has exactly 100 money. If this is true, then the max health will increase by 1. However, you may wish to check if money is greater than or less than 100. To do this, there is a new set of operators available specifically for commands. “>” means greater than, “<” means less than, “>=” means greater than or equal to, “<=” means less than or equal to, and “!=” means not equal to. Here how it works:

if money >= 100
max health + 1

The above example checks if the player’s money is greater than or equal to 100. If this is true, then the max health will increase by 1. Keep in mind that the conditional only checks for whatever sits below it. It does not check for everything below it. So, if you wish to purchase an extra health for 100 money, you could try this:

if money >= 100
max health + 1
if money >= 100
money -100

However, there is an easier way. You can group a list of commands together using curly brackets which will all count under a single conditional. It would look like this:

if money >= 100
{
max health + 1
money – 100
}

The above example will increase max health by 1 and remove 100 money if money is greater than or equal to 100. If money is less than 100, nothing will happen. (For those of you who have used code in the past, please note that the curly brackets must be placed on their own line.)

You can ask several conditionals using “&” for and or “|” for or. For example:

if money > 99 | health = 1
{
max health + 1
money -100
}

The above example checks if money is greater than 99 or if the character has only 1 health left. If either of these conditionals are true, then the commands within the brackets will apply. If both conditionals are not true, then nothing will happen. Here is another example:

if money > 99 & max health != 3 & double jump = true
{
max health + 1
money – 100
}

The above example checks that money is greater than 99, max health is something other than 3, and if the character can double jump. If all three of these things are true, then the commands within the brackets will apply. If any of those three conditionals are not true, then nothing will happen. (Note that Platform Builder does not support the use of parentheses to group these things together.) Alternatively, you can use “and” and “or” to pair your conditionals.

if money > 99
and max health != 3
and double jump = true
{
max health + 1
money – 100
}

The above example works the same way as the example before it.
There is a special conditional, “else,” which will be considered true if the conditional(s) before it were false, and vice versa. It works like this:

if money > 100 | money = 100
{
max health + 1
money -100
}
else
{
+You don’t have enough money!
}

The above example checks if money is greater than or equal to 100. If this is true, then max health goes up by 1 and money decreases by 100. If it is not true, then a message says “You don’t have enough money!” (The second set of curly brackets is not necessary since there is only a single command after the else conditional, but it won’t hurt anything.) Note that you cannot add other conditionals to “else” using “&” or “|”

On the command prompt page, we learned that you can place certain things in brackets to get their value. This is useful for conditionals and commands. For example:

if health = [max health]
+You already have full health!
else
{
health = [max health]
+Your health has been restored to [health]!
}

The above example checks if health is equal to the max health. If it is, then a message displays telling you that you are already at full health. If not, then your health is fully restored to the maximum health, and a message displays telling you the new amount of health that you have.

Note that conditionals are a little more space-sensitive than commands, so try to be more careful.

  • Almost any command can be used as a conditional. For example:
    “swim style = standard” becomes “if swim style = standard”
    “background = forest 1” becomes “if background = forest 1”
    “snow = false” becomes “if snow = false”
    “game var 5 = 20” becomes “if game var 5 = 20”
    “area = 3, Start1” becomes “if area = 3”

There are also some special conditionals that do not look like any other command. They are already available on the main command prompt page, but we will list them here again.