Inline Conditions for Ren'Py
A downloadable asset pack
Overview
Consider the following situation:
if apples == 1: "You set it on the table." else: "You set them on the table."
This is a lot of code for an extremely minor line variation. Some other engines for text-based projects like Twine Sugarcube have inline conditional statement syntax to reduce this sort of thing down to one line of dialogue. And now you can have this functionality in Ren'Py too, using this addon!
"You set {if apples == 1}it{else}them{/else} on the table."
Description
This Ren'Py addon provides:
- Text tag-like syntax to use conditions in dialogue and in choice menus
- Skip seen text only compatibility - two different syntax variations let you decide whether the line should be considered unseen if the player hasn't seen a particular combination of conditions, or if it's still considered the same line for skipping.
- Choose which behaviour you want as the default, with the option to use the other behaviour on a per-condition basis
- Any combination of if/elif/else is possible
- Compatible with translations
An optional lint file is included for a small additional fee. This file performs a regular lint check, but with additional options for linting the inline conditional statements for correctness + a count of how many inline conditions you're using across your whole project.
Features
Free File | Extra Paid File |
{if}, {elif}, {else} text tags, and special {skip_if} and {stop_if} variants Explanatory comments and examples Code to remember which versions of the line have been viewed, for use with the "skip unseen" setting An updated Skip screen action which behaves correctly for use with inline conditionals and the "skip unseen" setting | 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 conditionals for correctness - it will let you know if you have a poorly-formed condition that would cause an error. Optionally, you can set the lint function to also report variables which are used in your inline conditionals but are not declared beforehand. The produced lint file also includes a count at the bottom of the number of inline conditional statements in the project. The condition correctness check and number of inline conditional checks 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 inline conditionals as erroneous text tags. |
Use
Simply place inline_conditions.rpy into your game folder and you can start writing inline conditional statements. Near the top of the file, after the examples, you can set inline_conditions_same_for_skipping to True or False to control what behaviour the inline conditions have by default for skipping.
"It's a{if gift == 'apron'}n{elif gift == 'earrings'} pair of{/elif} [gift]."
This code is roughly equivalent to:
if gift == 'apron': "It's an [gift]." elif gift == 'earrings': "It's a pair of [gift]." else: "It's a [gift]."
Because the condition is inline, unlike the very verbose version above, you have the option of treating it as a singular line when it comes to skipping. It's also treated as a single line for translation - this can even reduce unneeded lines, particularly in cases where a line would not need to have a variation due to one language not differentiating between plural and singular nouns. Inline conditions cut down on unnecessary variable declarations, and provide a smoother experience for readers who won't find skipping suddenly stops for a minuscule line difference.
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.
For 8.1 and Earlier:
Inline conditions will cause lint errors in versions earlier than 8.2, as presently Lint does not account for text filters when linting text, thus it does not recognize the text tags. Lint also does not check the conditions 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 conditions - this fee is so I can continue to maintain the linter even if the engine updates how linting is handled. You will run the lint in-game instead of from the launcher.
For 8.2 and Later:
Linting has been updated in 8.2 to apply filters to the text before reporting errors. This means that if you have the additional lint files in your project, you can use Lint from the launcher and the additional lint tests for conditions will work as a regular lint hook.
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, it also includes functions for linting inline Python, which you can find linked below. Both inline conditions and inline Python 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
Status | Released |
Category | Assets |
Rating | Rated 4.5 out of 5 stars (10 total ratings) |
Author | Feniks |
Genre | Interactive Fiction, Visual Novel |
Made with | Ren'Py |
Tags | Kinetic Novel, Modular, Ren'Py, sourcecode |
Download
Click download now to get access to the following files:
Development log
- 8.2 Lint UpdateFeb 06, 2024
- Inline Linting UpdateJan 09, 2024
- Inline Python is Released!Aug 19, 2023