Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
def replace_text(s):
s = s.replace("'", u'\u2019') # apostrophe
s = s.replace('--', u'\u2014') # em dash
s = s.replace('...', u'\u2026') # ellipsis
return s
config.replace_text = replace_text
I want to use it, but I have a concern about performance.
It says that all text will run through a replacement function if you use it, and from what I know string operations are notorious performance-eaters. I can't confirm or deny this, since my computer is very beefy and I don't own a less beefy one to test it with. I'm not talking about toaster-grade, but average PC or laptop.
1) It is only ran on each piece of text one at a time
2) Those pieces of text are generally pretty short (even in triple quoted string soliloquies)
3) Dialogue progression in a VN generally leaves loads of time for the engine to perform operations like this... It's not like we have to do it between each frame of a 4k game running at 200fps
4) Python is rather well optimized for string searching and replacement as it goes (it is heavily used in many high level AI/ML systems for that reason)
5) If your search=>replace dict was huge you could always use regex within the function to improve performance... Realistically though, you are only really going to be using this to control player inputted information... otherwise, just fix your script instead...
I see, thank you for the insight. So it seems harmless.
I just wanted to mostly replace all the "--" in my script with em dashes and this seemed like an easy way to do it. Perhaps I can find another way though (MS Word or something), now that I have my script all compiled in a single document (for editing, not for the actual game).
I'd just use any program that will keep the line encoding as is, and has a find/replace feature.
A quick once-over by your editor or proof reader (you, usually) and you should be all good. I've only ever had to fix a few issues with find/replace, most of the time its a simple job.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
As Imperf3kt indicates, you CAN put Unicode characters directly into Ren’py scripts if your editor understands UTF8-encoded files.
Alternately, if you want to stick with ASCII-encoded files, you can use Unicode escapes - if you put \u2014 inside a string, it will be rendered as an em dash. The backslash-u is the beginning of a Unicode escape, and 2014 is the hexadecimal code for an em dash. I tend to do it this way because of some automated tools I have for dealing with Ren’py scripts, and sticking with ASCII encoding is easier with them. I use the escape sequences for curly-quotes, apostrophes, etc.