Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Inline Conditions for Ren'Py

Use if/else logic right inside dialogue lines in Ren'Py · By Feniks

Need Support? Post here! Sticky

A topic by Feniks created Aug 14, 2023 Views: 214 Replies: 18
Viewing posts 1 to 4
Developer

If you're having trouble or run into any bugs with the code, post a comment here! I will try to get back to you within a few days.

Hey, I think inline comments were working for a while for me, but suddenly they just stopped working. For some reason it's not recognizing the if tags and raises an error that else was used without a corresponding if. Here's an example where it fails: 

Any idea what might've broken and how to fix it?

Ah, I think I got it. If I use the inline comment in an "extend" statement, it fails to register the if. It only works on non-extend dialogue rows. Will support for extend lines be added to the plugin or should I just make sure to always use it on one-liners?

Developer

Hmm, can you clarify with an example? Are you splitting up the if/else across the extend line? 

Yeah, I can give and example. And no, the if is on one line, but I'm splitting the character's lines to different lines, so that the player will have to press a key for the rest of it to print out.

player "Well, well..."
extend " If it isn't the consequences of {if _act==True}my{else}your{/else} actions."

The one above would throw an error, but the one below would be fine.

player "Well, well... If it isn't the consequences of {if _act==True}my{else}your{/else} actions."

Developer(+1)

Thanks! I'm looking into it, but unfortunately it doesn't look like it'll be a simple fix. In the meantime, not having inline conditions in an `extend` line seems to be the way to go. I'll reply to you if I figure out a solution!

Hi! I just added the lint files into my project and now I'm getting an error when trying to run lint both from the launcher and from the ingame button. 

Developer

Which version of Ren'Py are you on? If it's earlier than 8.2, you will need to use the in-game lint option (rather than the one from the launcher) due to how Ren'Py parses dialogue for lint. If you're on 8.2, show me the error from running Lint on the launcher. If you're on 8.1 or earlier, show me the error from running Lint in-game.

Sure, I'm using Renpy 8.0.3 and I used in game button to start the lint. I apologise for bothering you with this. ^^;

[code]

I'm sorry, but an uncaught exception occurred.

While running game code:

  File "renpy/common/00action_other.rpy", line 578, in __call__

    rv = self.callable(*self.args, **self.kwargs)

  File "game/custom_lint.rpy", line 196, in lint

    node.what = renpy.config.say_menu_text_filter(node.what)

  File "game/inline_conditions.rpy", line 469, in add_conditional_tags

    raise Exception("ERROR: Closing {/if} tag without corresponding {if}")

Exception: ERROR: Closing {/if} tag without corresponding {if}

-- Full Traceback ------------------------------------------------------------

Full traceback:

  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script

    python hide:

  File "D:\renpy-8.0.3-sdk\renpy\ast.py", line 1131, in execute

    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)

  File "D:\renpy-8.0.3-sdk\renpy\python.py", line 1061, in py_exec_bytecode

    exec(bytecode, globals, locals)

  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>

    python hide:

  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide

    ui.interact()

  File "D:\renpy-8.0.3-sdk\renpy\ui.py", line 299, in interact

    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)

  File "D:\renpy-8.0.3-sdk\renpy\display\core.py", line 3377, in interact

    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore

  File "D:\renpy-8.0.3-sdk\renpy\display\core.py", line 4258, in interact_core

    rv = root_widget.event(ev, x, y, 0)

  File "D:\renpy-8.0.3-sdk\renpy\display\layout.py", line 1175, in event

    rv = i.event(ev, x - xo, y - yo, cst)

  File "D:\renpy-8.0.3-sdk\renpy\display\transition.py", line 53, in event

    return self.new_widget.event(ev, x, y, st) # E1101

  File "D:\renpy-8.0.3-sdk\renpy\display\layout.py", line 1175, in event

    rv = i.event(ev, x - xo, y - yo, cst)

  File "D:\renpy-8.0.3-sdk\renpy\display\layout.py", line 1175, in event

    rv = i.event(ev, x - xo, y - yo, cst)

  File "D:\renpy-8.0.3-sdk\renpy\display\screen.py", line 743, in event

    rv = self.child.event(ev, x, y, st)

  File "D:\renpy-8.0.3-sdk\renpy\display\layout.py", line 1175, in event

    rv = i.event(ev, x - xo, y - yo, cst)

  File "D:\renpy-8.0.3-sdk\renpy\display\behavior.py", line 1073, in event

    return handle_click(self.clicked)

  File "D:\renpy-8.0.3-sdk\renpy\display\behavior.py", line 1008, in handle_click

    rv = run(action)

  File "D:\renpy-8.0.3-sdk\renpy\display\behavior.py", line 329, in run

    return action(*args, **kwargs)

  File "renpy/common/00action_other.rpy", line 578, in __call__

    rv = self.callable(*self.args, **self.kwargs)

  File "game/custom_lint.rpy", line 196, in lint

    node.what = renpy.config.say_menu_text_filter(node.what)

  File "game/inline_conditions.rpy", line 469, in add_conditional_tags

    raise Exception("ERROR: Closing {/if} tag without corresponding {if}")

Exception: ERROR: Closing {/if} tag without corresponding {if}

Windows-10-10.0.19045 AMD64

Ren'Py 8.0.3.22090809

CoT:TheRemainder_playtest 0.66

Tue Jul 30 13:06:24 2024

[/code]

Developer

Alright, and can you show me some of the code where you use the inline conditions? Particularly anywhere you have {/if} written, as the error indicates it can't find a corresponding opening tag. This can sometimes happen if the filter has been executed twice, but if you're on 8.0.3 and running from in-game that shouldn't be an issue.

Having two issues:

The main one is Lint is crashing Renpy (not when I launch the Game itself, but when I am trying to Lint). I would get an error message of:

While running game code: File “game/defines/inline_conditions.rpy”, line 483, in add_conditional_tags raise Exception(“ERROR: Closing {/else} tag without corresponding {else}”) Exception: ERROR: Closing {/else} tag without corresponding {else}

With a whole bunch of lines without telling me what Rpy file and what line this error was reported from, I searched for {/else} throughout the entire project. I did make some changes to add {/else} where appropriate that I somehow missed, but to no avail. Now if I build and launch a game, not getting this crash.

So I tried to use the lint and the Launcher (tried 8.2.4 and 8.3), which gives this exception. However, the custom.txt gives this line:

Exception when trying to add inline Python linting: cannot import name ‘parse_general_expression_ver1’ from ‘store’ (unknown location)

Developer

Can you share a sample of the way you're writing some of your inline conditions? I talked more with Nim above offsite and you may be experiencing the same issue.

jw “{if tempcallb}[tempchar]{else}[rw]{/else}, {if tempcallb}take a search party to find our missing {if len(templist)>1}wolves{else}wolf{/else}{if not tempcallb}secure the premise”

mc_t “”” An eldritch wave crashed into the wards!

    Some slipped through...

    {if eldbool}But I seemed to be fine{else}Ugh, the headache from that{/else}

“””

Ok, narrowed down here issues are occuring. Moved the TL folder to a temporary folder. Now it is no longer crashing.

Ok, it had problems with evaluating a dictionary, which I solved by turning it into a temporary bool. The erroneous error message (sorry, but it is misleading) was likely triggered by the same error occurring in the translations.

deleted the problem code from the translation files, and now it is no longer giving me that crash.

Developer (1 edit)

Edit: lol I missed there were more responses as I had to step away and didn't refresh the page. Thank you for the updates! I'll leave my original response here anyway, and I do intend to see if I can have better line returns for errors.

Hmm, this seems fine to me. The custom.txt line is irrelevant; it's just checking if you've got the inline python tool installed and need linting for it.

How are you running the linter? From the launcher lint option, or from an in-game button? 8.2+ properly parses lines using the say_menu_filter, so you can run it from the launcher rather than the custom in-game button.

My other thought is possibly that you have an {else} split up across multiple monologue lines - these are considered individual lines when considering text tags, rather than one text block, so an {else} that was left open, then two newlines to begin the next line, will not continue the {else} tag.

I'll see if I can modify the linter to return an actual line to look at as well!

Thank you for the response. Basically, I should run Lint before I run Generate Translations. ;) Once I got rid of the TL folder temporarily, Lint was able to capture the lines that were causing a problem.

Is it possible to just have your Linter just ignore anything in TL folders? Because if it checks through the code and go “Hey, we are having a problem parsing the line”, the moment you fix it, you got to generate a new translation anyways because Renpy will change the translation id and require you to create a new one. :)

My thought for ignoring the TL folder might not be a good idea. As I have come up with a few in the last few hours where I made a tag mistake (a { or } got deleted by accident)