Renpy coding help - Capitalization

MTY Games

Newbie
Game Developer
Jan 12, 2019
55
90
Just wondering if a Renpy Master can help me out here.

Trying to get renpy to change the stored povname into all capitals for a single phrase. For example

Code:
define p = Character("[povname]")
define m = Character("Mom")

# At a later stage in the game

m "[povname]!!!" #<------ I want the mom to shout the name all in capitals.

I've found a few things dotted round the net about using python strings, but i'm stupid and don't know how to code them in.

Any help would be muchly appreciated!!
 

dave619

Member
Nov 3, 2018
457
179
Just wondering if a Renpy Master can help me out here.

Trying to get renpy to change the stored povname into all capitals for a single phrase. For example

Code:
define p = Character("[povname]")
define m = Character("Mom")

# At a later stage in the game

m "[povname]!!!" #<------ I want the mom to shout the name all in capitals.

I've found a few things dotted round the net about using python strings, but i'm stupid and don't know how to code them in.

Any help would be muchly appreciated!!
Have you looked on renpy website I think the coding is there
 
Oct 30, 2018
395
1,143
I'm but a mere Ren'Py padawan, but I think this should work.

$ capitalname = povname.upper()

You can create a variable to store your capitalized name using the Python .upper() method. Then simply interpolate that new variable into your dialog

m "[capitalname] !!!!"

Edit: got my initial syntax wrong because I'm an idiot , changed
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,688
I tried what @Dicks McKenzie suggests just for fun and to learn news things of renpy... but I get an error "'ADVCharacter' object has no attribute 'upper' "

So, I've been doing some tests, and for what it's worth, you can also use this (although this changes the whole sentence, not just one word... unless you can change a variable in the middle of a text, I don't know if it's possible).

This is default part in screens.rpy
Code:
screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
You can change this part like that:
Code:
screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        if caps == True:
            text what.upper() id "what"
        else:
            text what id "what"
Then in your script, add the "caps" variable:
Code:
default caps = False
And to use it in your text lines simply change this variable... for example:
Code:
label start:
     m "Hello world"   #normal text
     $ caps = True
     m "[povname]!!!"    #This will all be shown in capital letters
     $ caps = False
     m "Bye world"   #normal text
 
  • Like
Reactions: MTY Games

MTY Games

Newbie
Game Developer
Jan 12, 2019
55
90
I tried what @Dicks McKenzie suggests just for fun and to learn news things of renpy... but I get an error "'ADVCharacter' object has no attribute 'upper' "

So, I've been doing some tests, and for what it's worth, you can also use this (although this changes the whole sentence, not just one word... unless you can change a variable in the middle of a text, I don't know if it's possible).
It works!!! Thanks so much, really appreciate it!
 
  • Like
Reactions: Porcus Dev
Oct 30, 2018
395
1,143
I'm not sure why you're getting an error. I did a quick test and .upper() should work fine against the character name variable.

I wrote a simple Ren'Py script:

Code:
define p = Character("[povname]")

label start:

    $ povname = "test"
    $ capname = povname.upper()

    p "[capname]"

    return
The output:
You don't have permission to view the spoiler content. Log in or register now.

Your solution is good too, mind. I'm just curious as to why mine failed on your end.
 
  • Like
Reactions: Porcus Dev

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,163
14,878
I'm not sure why you're getting an error. I did a quick test and .upper() should work fine against the character name variable.
It works fine with the character name, but that's not what you do when you write "p.upper()" :

Code:
define p = Character( "test name" )

label start:
    # Let Ren'py display the string form of the "p" object.
    "[p]"

    # Try to use the "upper" method of the "p" object.
    python:
        try:
            txt = p.upper()
        except:
            txt = "You got an Error"
    "[txt]"

    # Representation of the object
    $ txt = repr( p )
    "[txt]"

    # String form of the object
    $ txt = str( p )
    "[txt]"

    # Upper version of the string form of the object
    $ txt = str( p ).upper()
    "[txt]"

    # Directly access the name of the object.
    $ txt = p.name
    "[txt]"

    # Apply the "upper" method of the string object stored in 
    # the "name" attribute of the "p" object.
    $ txt = p.name.upper()
    "[txt]"

    return
Now, the prettiest answer to the question is to update the Character object :
Code:
init python:
    # The function to add as method.
    # Like it's a method, it will have the object reference as very first
    # parameter.
    def upperName( self ):
        # Use the object reference to access the name, and return a
        # all uppercase version of it.
        return self.name.upper()

    # store.Character is in fact a store.ADVCharacter object.
    # Update it by adding a property named "NAME" (all uppercase 
    # to explicitly represent what it do).
    # This must be a property because we are expected to directly
    # access it as a value, not to call it. So, just defined the "getter"
    # which is the function silently called to get the value of this
    # property.
    ADVCharacter.NAME = property( upperName )

define p = Character( "test name" )
define g = Character( "another name" )

label start:
    # And now at anytime, if you address the "NAME" attribute of a
    # character, you'll get its name in full uppercase.
    "[p.NAME] [g.name]"
    return
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,688
It works fine with the character name, but that's not what you do when you write "p.upper()" :

Code:
define p = Character( "test name" )

label start:
    # Let Ren'py display the string form of the "p" object.
    "[p]"

    # Try to use the "upper" method of the "p" object.
    python:
        try:
            txt = p.upper()
        except:
            txt = "You got an Error"
    "[txt]"

    # Representation of the object
    $ txt = repr( p )
    "[txt]"

    # String form of the object
    $ txt = str( p )
    "[txt]"

    # Upper version of the string form of the object
    $ txt = str( p ).upper()
    "[txt]"

    # Directly access the name of the object.
    $ txt = p.name
    "[txt]"

    # Apply the "upper" method of the string object stored in
    # the "name" attribute of the "p" object.
    $ txt = p.name.upper()
    "[txt]"

    return
Now, the prettiest answer to the question is to update the Character object :
Code:
init python:
    # The function to add as method.
    # Like it's a method, it will have the object reference as very first
    # parameter.
    def upperName( self ):
        # Use the object reference to access the name, and return a
        # all uppercase version of it.
        return self.name.upper()

    # store.Character is in fact a store.ADVCharacter object.
    # Update it by adding a property named "NAME" (all uppercase
    # to explicitly represent what it do).
    # This must be a property because we are expected to directly
    # access it as a value, not to call it. So, just defined the "getter"
    # which is the function silently called to get the value of this
    # property.
    ADVCharacter.NAME = property( upperName )

define p = Character( "test name" )
define g = Character( "another name" )

label start:
    # And now at anytime, if you address the "NAME" attribute of a
    # character, you'll get its name in full uppercase.
    "[p.NAME] [g.name]"
    return
Awesome!
 

MTY Games

Newbie
Game Developer
Jan 12, 2019
55
90
Now, the prettiest answer to the question is to update the Character object :
Does this change the characters name to capitals or change what that character says into capitals? If not the latter then do you know a way to do this?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,163
14,878
Does this change the characters name to capitals or change what that character says into capitals? If not the latter then do you know a way to do this?
It answer the question you asked when starting this thread. When you write something like :
Code:
girl "Hey, [p.NAME], how are you"
The name of the "p" character will be displayed in uppercase in the sentence.
 
  • Like
Reactions: MTY Games

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,559
2,176
The name of the "p" character will be displayed in uppercase in the sentence.
I liked this solution... with only one problem...
It doesn't work if the name of the character is a variable.

I wrote this testbed code before I realized it didn't quite do what I was expecting it to.

You don't have permission to view the spoiler content. Log in or register now.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,163
14,878
I liked this solution... with only one problem...
It doesn't work if the name of the character is a variable.
Arg, dynamic killed me... Well, in fact not for long, just a little fix :
Code:
    def upperName( self ):
        return renpy.substitutions.substitute( renpy.python.py_eval( self.name ) if self.dynamic else self.name )[0].upper()
 
  • Like
Reactions: 79flavors

Silk_Ari

Active Member
Game Developer
Dec 21, 2017
707
1,844
This thread is old, but I was looking for this and I personally found the best solution to be:

step 1 create a temp variable:
define UpperName = "empty"

Then in your script, when you need an uppercase name:
$ UpperName = povname.upper()
povname "My name is [povname] and in uppercase is: [UpperName]"
$ UpperName = character.upper()
character "My name is [character] and in uppercase is: [UpperName]"

if you need 2 uppercase names in the same sentence then just create another variable UpperName2.

hope this helps someone!
 

the66

beware, the germans are cumming
Modder
Respected User
Donor
Jan 27, 2017
7,611
23,575
ok, lets do the necro... :KEK:

1st: use an up-to-date Ren'Py version
2nd: there are flags for interpolating variables in Text objects.


in this case: m "[povname!u]!!!"
 

Silk_Ari

Active Member
Game Developer
Dec 21, 2017
707
1,844
ok, lets do the necro... :KEK:

1st: use an up-to-date Ren'Py version
2nd: there are flags for interpolating variables in Text objects.


in this case: m "[povname!u]!!!"
You know i tried that and it wasn't working... never thought to update my renpy :D

btw: The !u flag forces the text to uppercase and the !l flag forces the text to lowercase. The !c flag acts only on the first character, capitalizing it. These flags may be combined, for example using !cl would capitalize the first character, and force the remaining text to lowercase.