Conditional Statements in Ren’Py
Today I'm back to show you how to use variables in IF Statements.
If you didn’t see my last post about setting up variables I suggest checking it out so you know how to set up variables in Ren’Py.
If you already know then please Read On!
Today I’m going to talk about mainly Conditional IF Statements in Ren’Py but they pretty much work the same way in most programs.
There are a couple of levels of IF Statements so we are gonna take them one at a time as they build upon each other.
Conditional Statements are pretty simple. They pretty much break down to - If the condition is met/true then do this action.
So that could be extra dialogue, jumping to a new section, unlocking a picture or a whole bunch of other functions. Today we are just going to look at it as adding extra text.
If the condition (If Condition) is met (True) then do this action (If Block) then continue on (Continued Text).
If the condition (If Condition) is not met (False) then continue on (Continued Text).
So this means that if the stoic variable is True it displays:
If the stoic variable is False then it displays:
If the condition (If Condition) is met (True) then do this action (If Block) then continue on (Continued Text).
If the condition (If Condition) is not met (False) then do this action (Else Block) then continue on (Continued Text).
So this means that if the stoic variable is True it displays:
Start Text
Stoic Text
Continued Text
If the stoic variable is False then it displays:
This allows you to still add extra text not attached to a variable.
But what if you want different text to display for different variables. For Example Stoic, Funny or Charming.
(Shortened to Elif - 'el'se 'if' = elif)
Also known as If Else If Statements
If the condition (If Condition) is met (True) then do this action (If Block) then continue on (Continued Text).
If the condition (If Condition) is not met (False) then go to (Elif Condition) and if this condition is met (True) then do this action (Elif Block) then continue on (Continued Text).
If the (If Condition) and (Elif Condition) are not met (False) then got to (Else condition), then continue on to (Else Block) then (Continued Text).
Ok, I get this looks pretty complicated but lets break it down!
So this means that if the stoic variable is True it displays:
Start Text
Stoic Text
Continued Text
If the stoic variable is False then it continues on to charming variable and if that variable is True it displays:
Charming Text
Continued Text
If both the stoic variable and charming variable are False then it continues on to the else section and displays:
So the easiest way to describe it i can think of is.
If this is not true go to next elif statement.
Repeat down the list until a statement is true or you get to the else statement.
Important! - You can not display more than one statement at a time and it will always display the first one it finds to be true. So even if the stoic variable and charming variable are both true it will only display the stoic text because that’s the first statement it came across.
You can do as many elif statements as you want just remember once it finds one that’s true it will use that.
Using If statements is a great way to flavour dialogue or text and it’s very usefully in branching pathways of text and gameplay.
YOU DID IT! You got to the end.
I know it might seem like a bit to take in, but once you get the hang of it you will be using IF Statements like a pro.
In the upcoming posts I will be looking more in depth into the different types of Variables you can use in Ren’Py and why you would use them.
Thanks for reading!