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.
-
arty
- Regular
- Posts: 120
- Joined: Sat Jan 06, 2018 11:55 am
- Completed: White Monday
- Projects: HATE is a 4 Letter Word
- Organization: KATHARSIS ART
- itch: artys-games
-
Contact:
#1
Post
by arty » Fri Feb 14, 2020 12:05 pm
Hi!
I recently discovered the
config.replace_text variable in the Ren'Py documentation:
Code: Select all
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.
Anyone got experiences/advice with this?
Cheers,
arty
-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#2
Post
by Remix » Fri Feb 14, 2020 5:45 pm
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...
Why were you seeking to use it?
-
arty
- Regular
- Posts: 120
- Joined: Sat Jan 06, 2018 11:55 am
- Completed: White Monday
- Projects: HATE is a 4 Letter Word
- Organization: KATHARSIS ART
- itch: artys-games
-
Contact:
#3
Post
by arty » Sat Feb 15, 2020 5:04 am
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).
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#4
Post
by Imperf3kt » Sat Feb 15, 2020 5:23 am
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.
Current project:
GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
-
rames44
- Veteran
- Posts: 232
- Joined: Sun May 29, 2016 4:38 pm
-
Contact:
#5
Post
by rames44 » Sat Feb 15, 2020 12:53 pm
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.
Users browsing this forum: Bing [Bot], Google [Bot], span4ev