Note that is pages discusses statements that can be used inside Ren'Py script. Python code embedded in a Ren'Py game uses the Python while, if, and for statements, but can't embed Ren'Py script code.
The if statement conditionally executes a block of code if a python
expression is true. It consists of an
if clause, zero or more
clauses, and an optional``else`` clause.
Each clause should be on its own logical line, followed by a block of
elif clauses are followed by an expression,
while all clauses end with a colon. (:)
if flag: e "You're set the flag!"
if points >= 10: jump best_ending elif points >= 5: jump good_ending elif points >= 1: jump bad_ending else: jump worst_ending
The expressions in the if statement are evaluated in order, from first to last. When an expression evaluates to true, the block corresponding to that statement is executed. When control reaches the end of the block, it proceeds to the statement following the if statement.
If all expressions evaluate to false, the block associated with
else clause is executed, if the
else clause is present.
The while statement executes a block of code while an expression evaluates true. For example:
$ count = 10 while count > 0: "T-minus [count]." $ count -= 1 "Liftoff!"
while True: "This is the song that never terminates." "It goes on and on, my compatriots."
The expression is evaluated when while statement is first reached, and then each time control reaches the end of the block. When the expression return a false value, the statement after the while statement is executed.
Ren'Py does not have continue, break, or for statements. Continue and break statements can be replaced by jumps to labels placed before or after the while loop, respectively. The first example of a while loop, above, shows how a while loop can replace a for statement.
The pass statement can be used when a block is required, but no statement is suitable. It does nothing.
if points >= 10: "You're doing great!" elif points >= 1: pass else: "Things aren't looking so good."
# event.step() is a function that returns true while there are # still events that need to be executed. while event.step(): pass