Python statements and variables
This page is part of the GenPy Ren'Py learning path. It focuses on practical Ren'Py 8.x production and links each concept back to the GenPy workflow.
Learning goals
- Separate constants from save-state variables.
- Use inline Python for small state changes.
- Keep larger logic readable in python blocks or helper functions.
Core syntax
$python:definedefaultinit pythonrenpy.*
Runnable example
text
define e = Character("艾琳") # 角色:不变 → define
define DAYS_PER_WEEK = 7 # 常量 → define
default money = 0 # 玩家金钱:会变 → default
default flags = {"met_eileen": False}
default inventory = []Study outline
- Start with the smallest example for python statements and variables.
- Test the key terms in a clean Ren'Py project: $, python:, define, default.
- Move the pattern back into your real project only after the example runs.
- Use GenPy docs and validation to keep the feature connected to story, assets, and export readiness.
Common pitfalls
- Use default for save-state variables, not define.
- Avoid side effects that rollback or save/load cannot replay safely.
- Test the smallest working script before layering on visual or UI complexity.
- Run Ren'Py Lint before release builds, even when the script appears to run locally.
- Keep examples in standard .rpy files so they remain editable outside GenPy.
Official references
- Ren'Py official reference: https://www.renpy.org/doc/html/python.html
- Ren'Py official reference: https://www.renpy.org/doc/html/statement_equivalents.html
How this fits in GenPy
- Use the Variables and State Registry pages to keep project state visible.
- Use Code mode when you need exact Python/Ren'Py syntax.
Recommended GenPy docs:
