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.
-
strayerror
- Regular
- Posts: 154
- Joined: Fri Jan 04, 2019 3:44 pm
-
Contact:
#1
Post
by strayerror » Thu Apr 18, 2019 2:11 pm
Code: Select all
eileen 'Hello [nickname]!"
player "Hi, Eileen!"
eileen "[nickname]! You're always so cheerful, what's you secret?"
In cases where
nickname is a proper noun (
Bob, for example) this works just fine, however sometimes
nickname will not be a proper noun (
stranger for a contrived example). In the second replacement I'd like to capitalise the improper noun because it's the start of a sentence, is there anyway to achieve this short of having to maintain two variables and remember to use one at the start of sentences and the other everywhere else? I just know it's going to get confusing with that approach.

Last edited by
strayerror on Sun Apr 21, 2019 1:17 pm, edited 1 time in total.
-
rames44
- Veteran
- Posts: 232
- Joined: Sun May 29, 2016 4:38 pm
-
Contact:
#2
Post
by rames44 » Thu Apr 18, 2019 3:51 pm
Well, Python strings have a
capitalize() method that will convert the first character of a string to upper case.
https://www.geeksforgeeks.org/string-capitalize-python/
The trick is to use Pythonic "stuff" in say statements.
I came up with one VERY ugly way of doing it:
Code: Select all
define e = Character("Eileen")
label start:
$ foo = "foo"
$ e("{} gets capitalized".format(foo.capitalize()))
This takes advantage of the fact that having a character say something is equivalent to "calling" the character object with the item to be said. But, IMHO, this is SO ugly that two variables would be preferred. LOL
Of course, there may be a FAR simpler way of doing this that one of the local Ren'py/Python gurus can come up with...
-
plaster
- Regular
- Posts: 89
- Joined: Thu Jul 11, 2013 1:03 am
- Tumblr: plasterbrain
- Soundcloud: plasterbrain
- Location: Chicago
-
Contact:
#3
Post
by plaster » Thu Apr 18, 2019 8:19 pm
Assuming you always want your sentences to start with a capital letter, you could get away with this:
Code: Select all
define config.say_menu_text_filter = capitalize_string
init python:
def capitalize_string(what):
return what.capitalize()
-
strayerror
- Regular
- Posts: 154
- Joined: Fri Jan 04, 2019 3:44 pm
-
Contact:
#4
Post
by strayerror » Fri Apr 19, 2019 9:21 am
Thanks both, unfortunately
say_menu_text_filter is called prior to the substitutions, so that option doesn't quite work
I also realised that this issue is actually far more complex than first though as it really applies to the start of any sentence, even those that start in the middle of a line. Googling around it looks like sentence detection is far from "solved" and can differ significantly between languages, so I fear this isn't as solvable as I'd hoped. Might be that the best I can hope for is adding some sort of annotation
[nickname!c] or something for when a capitalised version is desired, if indeed it's possible to add annotations.
-
plaster
- Regular
- Posts: 89
- Joined: Thu Jul 11, 2013 1:03 am
- Tumblr: plasterbrain
- Soundcloud: plasterbrain
- Location: Chicago
-
Contact:
#6
Post
by plaster » Fri Apr 19, 2019 6:59 pm
You're right, that is a lot more complicated than I'd assumed... Having a capitalized version of the string either thru text tags or a second variable is probably your best bet, then...
-
strayerror
- Regular
- Posts: 154
- Joined: Fri Jan 04, 2019 3:44 pm
-
Contact:
#7
Post
by strayerror » Sun Apr 21, 2019 1:17 pm
Oooh, totally forgot about tags, that could work, thanks for the suggestions!
Users browsing this forum: Bing [Bot]