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.
Use if/else logic right inside dialogue lines in Ren'Py · By
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?
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."
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]
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)
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}
“””
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. :)