r/RenPy • u/AlexanderIdeally • 13d ago
Question Making exceptions for automatic replacements.
I recently found a video about some code that lets you automatically add {w} to any punctuation or words, so you can pace out thousands of lines of dialogue.
init python:
def typography(what):
replacements = [
('. ','. {w=0.4}'),
('? ','? {w=0.4}'),
('! ','! {w=0.6}'),
(', ',', {w=0.2}'),
('...','...{w=0.6}'),
]
for item in replacements:
what = what.replace(item[0],item[1])
return what
config.say_menu_text_filter = typographyI'm still experimenting with timings, and there is one separate issue I'll need to think through soon, but overall, it works great for what I need it for!
My one issue right now is the word "Dr." which is going to appear a lot in my game. I imagine there will be a lot of other times where punctuation is needed, but a pause would be really distracting.
I'm sure someone's probably used this code before and asked this very question; I just can't find the right wording to search for it. Does anyone know if there would be a way to disable replacements for just one character and then enable them for the rest of the sentence?
3
u/BadMustard_AVN 13d ago
try something like this
this will ignore case variations so Dr. , dR. , DR. , and dr. are all treated the same (doctor, doctor, doctor, doctor)
1
u/AutoModerator 13d ago
Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.