To allow Ren'Py to be scripted in python, each Ren'Py statement has equivalent Python code. This usually consists of a Python function, but may also consist of a code pattern that performs an action equivalent to the statement.
The Ren'Py say statement is equivalent to calling the character object as a function. The following code displays the same line twice:
e "Hello, world."
$ e("Hello, world.")
Displaying narration can be done the same way, by using the narrator character. When calling a character, it's possible to supply the keyword argument interact. When interact is false, Ren'Py will display the character dialogue box, and will then return before performing an interaction.
This equivalence of characters and function objects works in the other direction as well. It is possible to declare a python function, and then use that function in the place of a character object. For example, the following function uses a variable to choose between two characters.
define lucy_normal = Character("Lucy")
define lucy_evil = Character("Evil Lucy")
init python:
def l(what, **kwargs):
if lucy_is_evil:
lucy_evil(what, **kwargs)
else:
lucy_normal(what, **kwargs)
label start:
$ lucy_is_evil = False
l "Usually, I feel quite normal."
$ lucy_is_evil = True
l "But sometimes, I get really mad!"
A function used in this way should either ignore unknown keyword arguments, or pass them to a character function. Doing this will allow the game to continue working if Ren'Py adds additional keyword arguments to character calls.
The equivalent of the say statement.
This function is rarely necessary, as the following three lines are equivalent.
e "Hello, world."
$ renpy.say(e, "Hello, world.")
$ e("Hello, world.")
The menu statement has an equivalent Python function.
This displays a menu to the user. items should be a list of 2-item tuples. In each tuple, the first item is a textual label, and the second item is the value to be returned if that item is selected. If the value is None, the first item is used as a menu caption.
This function takes many arguments, of which only a few are documented. Except for items, all arguments should be given as keyword arguments.
This displays a menu to the user. items should be a list of 2-item tuples. In each tuple, the first item is a textual label, and the second item is the value to be returned if that item is selected. If the value is None, the first item is used as a menu caption.
This function takes many arguments, of which only a few are documented. Except for items, all arguments should be given as keyword arguments.
The image, scene, show, and hide statements each have an equivalent python function.
Returns the list of transforms being applied to the image with tag name on layer. Returns an empty list if no transofrms are being applied, or None if the image is not shown.
If layer is None, uses the default layer for the given tag.
Hides an image from a layer. The python equivalent of the hide statement.
Defines an image. This function is the python equivalent of the image statement.
This function may only be run from inside an init block. It is an error to run this function once the game has started.
The python equivalent of the show layer layer at at_list statement.
Removes all displayables from layer. This is equivalent to the scene statement, when the scene statement is not given an image to show.
A full scene statement is equivalent to a call to renpy.scene followed by a call to renpy.show(). For example:
scene bg beach
is equivalent to:
$ renpy.scene()
$ renpy.show("bg beach")
Shows an image on a layer. This is the programmatic equivalent of the show statement.
The python equivalent of the show layer layer at at_list statement.
The equivalent of the with statement is the renpy.with_statement function.
Causes a transition to occur. This is the python equivalent of the with statement.
This function returns true if the user chose to interrupt the transition, and false otherwise.
The equivalent of the jump statement is the renpy.jump function.
Causes the current statement to end, and control to jump to the given label.
The equivalent of the call statement is the renpy.call function.
Causes the current Ren'Py statement to terminate, and a jump to a label to occur. When the jump returns, control will be passed to the statement following the current statement.
Causes Ren'Py to return from the current Ren'Py-level call.