If, elif, else

The keywords if, elif, and else form the basic condition test in Ren'Py. The elif part can be omitted or repeated as needed. The else part is optional. Each condition is tested separately, and the first block of statements where the corresponding condition matches is run. The rest are not. If no conditions are True then the else statements are run.


if condition1:
    "Condition1 was true."
elif condition2:
    "Condition1 was False, condition2 was True."
elif condition3:
    "Condition1 and condition2 were False, condition3 was True."
else:
    "None of the conditions were True."

So what's a condition?

A condition is a Python expression that's tested to see if it's True. Without getting too bogged down the following are considered True:

Note: None is always considered to be False.

Order is important!

The order you test things in is important. It's the first match that will be selected, and the others ignored. Work from the most specific test to the least specific one. If making numeric comparisons work from one end consistently such as highest to lowest, or lowest to highest.


    if married:
        beth "Hi honey."
    elif engaged:
        beth "Hi love."
    elif bethRomance >= 75:
        beth "Hi sexy."
    elif bethRomance >= 40:
        beth "Hi handsome."
    elif bethRomance >= 10:
        beth "Hi [pcName]."
    else:
        beth "Hello [pcName]."

Don't be tempted to include unnecessary terms in your conditions. These have already been eliminated due to the ordering, and any errors could lead to the wrong block being chosen:


    if married:
        beth "Hi honey."
    elif not married and engaged:
        beth "Hi love."
    elif not married and not engaged and bethRomance >= 75:
        beth "Hi sexy."
    elif not married and not engaged and bethRomance < 75 and bethRomance >= 40:
        beth "Hi handsome."
    elif not married and not engaged and bethRomance < 40 and bethRomance >= 10:
        beth "Hi [pcName]."
    else:
        beth "Hello [pcName]."