Working with Ren’Py:
- Part 1: Downloading and Configuring
- Part 2: Editing and Creating Characters
- Part 3: Scenes and Showing Images
- Part 4: Menus, Labels, and Jumps
- Part 5: Variables and Conditional Statements
- Part 6: Transitions
- Part 7: Building Distributions
Advanced Ren’Py:
- Part 1: Screen Language
- Part 2: Position Style Properties
- Part 3: Animation and Transformation Language
- Part 4: Text and Button
- Part 5: Bar and VBar
- Part 6: Textbutton and Imagebutton
- Part 7: Input, Key, and Mousearea
Customizing Ren’Py:
- Part 1: Editing options.rpy
- Part 2: Editing gui.rpy
- Part 3: Style Inspector and Overriding Styles
- Part 4: Special Screen Names and Overriding Screens
- Part 5: Replacing Default GUI Images
Ren’Py + Python:
- Part 1: Setting and Using Flags
- Part 2: Python Blocks
- Part 3: User-Defined Displayables
- Part 4: User-Defined Statements
- Part 5: Custom Text Tags
Ren’Py is a engine for creating visual novels. It comes with a suite of tools for taking code and transforming it into programs that can be run on Windows, Mac, Linux, and even, with a little more work, mobile platforms like Android and iOS.
Beyond the showing of text and images, Ren’Py can also be extended through introducing new user interface elements, changing its defaults images, and combining Python with its own code to create even more interactive projects.
User-Defined Statements
Like Displayables, authors can also create their own statements.
Note: While user-defined disaplayables can be written within a script.rpy file before the start label, user-defined statements must be added BEFORE any other files that use them. Because Ren’Py loads files based on their names, it is highly recommended to use numbers in its filename.
User-defined statements need a minimum of three properties defined as functions: parse, parse the statement and return an object; execute, function that is called when the statement executes; and lint, checks the statement and should call renpy.error to report errors.
Note: User-defined statements must also use the python early block to signal that the statements should be parsed before any other.
GitHub Gist Version:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python early: | |
def parse_smartline(lex): | |
who = lex.simple_expression() | |
what = lex.rest() | |
return (who, what) | |
def execute_smartline(o): | |
who, what = o | |
renpy.say(eval(who), what) | |
def lint_smartline(o): | |
who, what = o | |
try: | |
eval(who) | |
except: | |
renpy.error("Character not defined: %s" % who) | |
tte = renpy.check_text_tags(what) | |
if tte: | |
renpy.error(tte) | |
renpy.register_statement("line", parse=parse_smartline, execute=execute_smartline, lint=lint_smartline) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define e = Character('Eileen', color="#c8ffc8") | |
label start: | |
line e "These quotes will show up," Eileen said, "and don't need to be backslashed." | |
return |