A downloadable asset pack

Download NowName your own price

Overview

If you've ever found yourself declaring temporary variables just for one line of dialogue or wishing dialogue had the flexibility of Python 3's fstrings, Inline Python for Ren'Py will provide the solution you need. Include anything from function calls to mathematics to conditional logic and more inside dialogue and choice menu text.

Note:

Inline Python is now included by default in Ren'Py versions 8.2+! I will be keeping this tool up for earlier versions of Ren'Py, but generally you should use the built-in interpolation instead for engine versions which support it. Read more about it here.

Description

Inline Python for Ren'Py offers two different formats for including Python directly inside dialogue and choice menu text. The first and default method uses <> to surround Python expressions, and the second uses a pseudo-text tag {expr:}. Both work identically, but the second is offered in case your script already uses a lot of <>. Incidental use of <> can be cancelled with a preceding backslash e.g. "\<this isn't an expression>."

Any Python expression found in dialogue will be run and substituted into the line just before it is shown to the player. An optional lint file is included, for a small additional fee. This lint file piggy-backs off of the lint for Inline Conditions for Ren'Py, so if you've bought the lint file for that listing, you do not have to re-purchase it here. Simply head to the Inline Conditions page to download the newly added lint file.

Features

Free File
Extra Paid File
<> format for inline Python, with the option to use a special {expr:} format instead

Explanatory comments and examples
A special lint function which can be executed in-game. Produces a regular lint file, but cleans up false positives you'd get when running Lint from the launcher.

This function will check your inline Python for correctness - it will let you know if you have a poorly-formed expression that would cause an error.

Optionally, you can set the lint function to also report variables which are used in your inline Python but are not declared beforehand.

The produced lint file also includes a count at the bottom with the number of inline Python expressions in the project. The expression correctness check and number of inline Python expressions will also work when Lint is used from the launcher, but note that a regular Lint will (as of 8.1/7.6) incorrectly report the {expr:} tag as erroneous. This does not occur with the default <> method.

Use

Place inline_expressions.rpy into your project's game/ folder and you can start writing inline Python expressions. Near the top of the file, after the examples, you can set parse_general_expression = parse_general_expression_ver1 to parse_general_expression = parse_general_expression_ver2 if you'd like to use the {expr:} format instead of <>.

In practice, inline Python looks like the following:

Method 1
Method 2
Result
"You have <player.get_HP()> HP left."

"You have {expr: player.get_HP()} HP left."
"You have 10 HP left." (presupposing a class method get_HP)
$ current_person = "xia"
$ points_dict = {"xia" : 10, "zoran" : 5, "ashwin" : 3}
"You have <points_dict[current_person]> points with [current_person!c]."
$ current_person = "xia"
$ points_dict = {"xia" : 10, "zoran" : 5, "ashwin" : 3}
"You have {expr: points_dict[current_person]} points with [current_person!c]."
"You have 10 points with Xia."

Note the use of a variable as a key, which causes an error with regular Ren'Py interpolation.

Compatibility

This code has been tested for compatibility with Ren'Py 7.5-7.6 and Ren'Py 8.0-8.2. It is expected to be compatible with earlier and later Ren'Py versions, and I'll maintain compatibility at least until Ren'Py adds a similar feature to the engine itself.

Inline Python is already included in the engine in 8.2+, so it's not recommended to use this tool over the built-in version.

The second version of this code, with the {expr:} pseudo-text tag, will cause lint errors, as lint does not currently account for text filters when linting text. Lint also does not check the Python expressions for correctness in any way. You can safely ignore lint errors which complain of unrecognized text tags. An additional file is also available for a small fee which adds a custom lint function to properly account for inline Python - this fee is so I can continue to maintain the linter even if the engine updates how linting is handled.

Terms of Use

Both the free version and any paid addons have the same terms of use.

You may:

  • Use this code in commercial and noncommercial projects, provided it is packaged into an archived .rpa file. The code to do so is included in the code files.
  • Modify and edit the code to suit your needs.

You may not:

  • Resell all or part of the code as-is or sell it with modifications
  • Release any projects created using this code without providing attribution

Attribution must be credited to Feniks, with a link to either the page with this code or to https://feniksdev.com

Final Notes

If you pay the minimum price for the lint file, you may also claim the linting file for my last tool, which brings inline conditions to Ren'Py. Both use the same approach to correctly lint the added formatting. Whether you download the bonus lint file here or on the other page, both contain the same files, so you do not have to pay twice!

Consider looking at my other Ren'Py tools, which I've added to a collection here: https://itch.io/c/3491447/my-renpy-tools and follow me to be sure you're notified of new releases and updates. I also release tutorials on my website, https://feniksdev.com

StatusReleased
CategoryAssets
Rating
Rated 5.0 out of 5 stars
(4 total ratings)
AuthorFeniks
GenreInteractive Fiction, Visual Novel
Made withRen'Py
TagsKinetic Novel, Modular, Ren'Py, sourcecode

Download

Download NowName your own price

Click download now to get access to the following files:

inline_expressions.zip 2 kB
inline_lint.zip 7 kB
if you pay $3 USD or more

Development log