Creator-Defined Statements link

Creator-defined statements allow you to add your own statements to Ren'Py. This makes it possible to add things that are not supported by the current syntax of Ren'Py.

Creator-defined statements must be defined in a python early block. What's more, the filename containing the user-defined statement must be be loaded earlier than any file that uses it. Since Ren'Py loads files in Unicode sort order, it generally makes sense to prefix the name of any file containing a user-defined statement with 01, or some other small number.

A user-defined statement cannot be used in the file in which it is defined.

Creator-defined statement are registered using the renpy.register_statement() function.

renpy.register_statement(name, parse=None, lint=None, execute=None, predict=None, next=None, scry=None, block=False, init=False, translatable=False, execute_init=None, init_priority=0, label=None, warp=None, translation_strings=None) link

This registers a user-defined statement.

This is either a space-separated list of names that begin the statement, or the empty string to define a new default statement (the default statement will replace the say statement).
When this is False, the statement does not expect a block. When True, it expects a block, but leaves it up to the lexer to parse that block. If the string "script", the block is interpreted as containing one or more Ren'Py script language statements. If the string "possible", the block expect condition is determined by the parse function.
This is a function that takes a Lexer object. This function should parse the statement, and return an object. This object is passed as an argument to all the other functions. The lexer argument has the following methods:
This is called to check the statement. It is passed a single argument, the object returned from parse. It should call renpy.error to report errors.
This is a function that is called when the statement executes. It is passed a single argument, the object returned from parse.
This is a function that is called at init time, at priority 0.
This is a function that is called to predict the images used by the statement. It is passed a single argument, the object returned from parse. It should return a list of displayables used by the statement.

This is a function that is called to determine the next statement.

If block is not "script", this is passed a single argument, the object returned from the parse function. If block is "script", an additional argument is passed, an object that names the first statement in the block.

The function should return either a string giving a label to jump to, the second argument to transfer control into the block, or None to continue to the statement after this one.

This is a function that is called to determine the label of this statement. If it returns a string, that string is used as the statement label, which can be called and jumped to like any other label.
This is a function that is called to determine if this statement should execute during warping. If the function exists and returns true, it's run during warp, otherwise the statement is not run during warp.
Used internally by Ren'Py.
True if this statement should be run at init-time. (If the statement is not already inside an init block, it's automatically placed inside an init block.) This calls the execute function, in addition to the execute_init function.
An integer that determines the priority of initialization of the init block.
A function that is called with the parsed block. It's expected to return a list of strings, which are then reported as being available to be translated.

The parse method takes a Lexer object:

class Lexer link
eol() link

True if the lexer is at the end of the line.

match(re) link

Matches an arbitrary regexp string.

All of the statements in the lexer that match things are implemented in terms of this function. They first skip whitespace, then attempt to match against the line. If the match succeeds, the matched text is returned. Otherwise, None is returned.

keyword(s) link

Matches s as a keyword.

name() link

Matches a name. This does not match built-in keywords.

word() link

Matches any word, including keywords. Returns the text of the matched word.


Matches an image name component. Unlike a a word, and image name component can begin with a number.

string() link

Matches a Ren'Py string.

integer() link

Matches an integer, returns a string containing the integer.

float() link

Matches a floating point number, returns a string containing the floating point number.

label_name(declare=False) link

Matches a label name, either absolute or relative. If declare is true, then the global label name is set. (Note that this does not actually declare the label - the statement is required to do that by returning it from the label function.)

simple_expression() link

Matches a simple Python expression, returns it as a string.

delimited_python(delim) link

Matches a pythio expression that ends in a delimiter, often ':' or '='.

arguments() link

Returns an object representing the arguments to a function call. This object has an evaluate method on it that takes an optional scope dictionary, and returns a tuple in which the first component is a tuple of positional arguments, and the second component is a dictionary of keyword arguments.

rest() link

Skips whitespace, then returns the rest of the line.

checkpoint() link

Returns an opaque object representing the current state of the lexer.

revert(o) link

When o is the object returned from checkpoint(), reverts the state of the lexer to what it was when checkpoint() was called. (This is used for backtracking.)

subblock_lexer() link

Return a Lexer for the block associated with the current line.

advance() link

In a subblock lexer, advances to the next line. This must be called before the first line, so the first line can be parsed.

Lint Utility Functions link

These functions are useful in writing lint functions.

renpy.check_text_tags(s) link

Checks the text tags in s for correctness. Returns an error string if there is an error, or None if there is no error.

Example link

This creates a new statement line that allows lines of text to be specified without quotes.

python early:

    def parse_smartline(lex):
        who = lex.simple_expression()
        what =
        return (who, what)

    def execute_smartline(o):
        who, what = o
        renpy.say(eval(who), what)

    def lint_smartline(o):
        who, what = o
            renpy.error("Character not defined: %s" % who)

        tte = renpy.check_text_tags(what)
        if tte:

    renpy.register_statement("line", parse=parse_smartline, execute=execute_smartline, lint=lint_smartline)

This can be used by writing:

line e "These quotes will show up," Eileen said, "and don't need to be backslashed."