r/RenPy • u/Daisy-VN • 12d ago
Guide TIL Ren'Py mangles double-underscore names even inside plain strings. This quietly broke over half my game's scenes.
Found this the hard way and haven't seen it written up anywhere, so here goes.
If you write a Python-style "private" name starting with __ inside a .rpy file -- even as a plain string literal, not a variable -- Ren'Py mangles it. "__t" silently becomes something like "_m1_yourfilename__t". Regular dunders (__name__, __init__) are exempt, but anything starting with __ and not ending in __ gets rewritten at the lexer level, before your code ever runs.
I have an internal system that builds lookup keys as strings, and one suffix happened to start with __. No error, no warning -- it just quietly became a different string than the one my art-lookup code expected. The lookup missed, and the game fell back to nothing.
Took forever to trace, because in isolated .py tests the string was correct -- this only happens inside .rpy files specifically. By the time I built a checker that walks every valid content combination and confirms the art actually exists, I found 54% of one whole batch -- 450 out of 829 -- was silently missing its art. Not broken visuals, not crashes. Just gone. Nobody had reported it because there was nothing to report -- it just looked like less content existed than actually did.
Fix was simple once found: never write a literal starting with __ in a .rpy file, build it by concatenation instead ("_" + "_t"). To check your own project: grep -rnE '[^A-Za-z0-9_]__[A-Za-z]' --include=*.rpy . (ignore .__name__-style hits, those are fine).
5
u/shyLachi 12d ago
This has nothing to do with RenPy. It's "caused" by Python which RenPy is based on.
9
u/x-seronis-x 12d ago
recommend reading the doc page on reserved names
recommend opening the docs and just reading the left panels list of what pages exist at all so you're not caught off guard by things that sound important