Ren'Py Renpy help needed for stat box and variables with names

Innocent Chloe

Active Member
Jul 23, 2017
549
902
Hey folks!

So I've started writing my first Renpy adult game and so far it has been going quite well except I am having a few issues that I've not been able to resolve by looking guides/videos and stuff online.

Issue 1;
I have a stats screen like below;
You don't have permission to view the spoiler content. Log in or register now.

But as you see as soon as I put a long text as the variable the text goes out of line, I could solve this by simplifying this and just putting it so it would be a single line but I really wanted for the stats screen to keep track of the event that happened so you always have it there as a mini-journal

This is the code for the stats screen;
You don't have permission to view the spoiler content. Log in or register now.


Then my second issue which is related to the stats screen again, I have defined character names as below;
You don't have permission to view the spoiler content. Log in or register now.

And I know that if you put for example as text in dialogue "%(f)s says hello to you" it would convert that to the name defined as f so in-game it would read as "Henry says hello to you"
But when in variables this doesn't seem to work and I can't find the code to reference a character name within a variable (players can input the names themselves thus why I need it to be linked to the defined name and not just write out the name myself)

So at the moment the line of code that links to that variable is;
You don't have permission to view the spoiler content. Log in or register now.


Thanks in advance!
 

guest1492

Member
Apr 28, 2018
350
288
It's not very elegant, but the only thing I can think of is to put in a ton of rows (ie hboxes). For example:
Python:
vbox:
    spacing 10

    hbox:
        vbox:
            xsize 100
            text "Virgin" size 40
        vbox:
            xsize 100
            text "[virgin]" size 40

    hbox:
        vbox:
            xsize 100
            text "First kiss claimed by" size 40
        vbox:
            xsize 100
            text "[firstkiss]" size 40

    # etc
As for the second issue, can't you simply do this?
$firstkiss = f.name + " in the shower after shaving you"
 
  • Like
Reactions: Innocent Chloe

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,201
But as you see as soon as I put a long text as the variable the text goes out of line, [...]
Ren'Py only break a line when there's not enough space to display the text on one line. Therefore, either your screen is wider than the game window, or you gave it a width too small.


But when in variables this doesn't seem to work and I can't find the code to reference a character name within a variable (players can input the names themselves thus why I need it to be linked to the defined name and not just write out the name myself)
Code:
label whatever:
    mc "[f] says hello to you"

So at the moment the line of code that links to that variable is;
You don't have permission to view the spoiler content. Log in or register now.
This will not works as it, because "firstkiss" is already displayed through .
You should have $ firstkiss = "[f] in the shower after shaving you" and text "[firstkiss!i]".


Edit: Fixed a typo in the code.
 
Last edited:

Innocent Chloe

Active Member
Jul 23, 2017
549
902
As for the second issue, can't you simply do this?
$firstkiss = f.name + " in the shower after shaving you"
This works! It is a great workaround if I can't get another method working and I've tested with doing it with multiple characters and splitting up the sentence and it works - but for some reason it doesn't work with one character name and I don't quite understand why.....

So these are my defined characters;
Code:
define p = Character('Chloe', color="#FF69B4") ##HotPink
define m = Character('Cassandra', color="#BC8F8F") ##RosyBrown
define f = Character('Henry', color="#6495ED") ##CornflowerBlue

And when I put the variable like this;
Code:
$firstkiss = "In the shower with " + m.name + " after " + f.name + " happened"
It works;
You don't have permission to view the spoiler content. Log in or register now.

But when I change it to be p.name it gives errors (even if I remove the other names and just have it in the format you initially showed with p.name + " in the shower"
Code:
$firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
It gives this error then;
Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 368, in script
    $firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
  File "game/script.rpy", line 368, in <module>
    $firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
AttributeError: 'unicode' object has no attribute 'name'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 368, in script
    $firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
  File "renpy/ast.py", line 928, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2245, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 368, in <module>
    $firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
AttributeError: 'unicode' object has no attribute 'name'

Windows-10-10.0.19041
Ren'Py 7.4.11.2266
Teen Adventures: Village Life 0.1
Fri Jul 29 14:43:02 2022

But I've found the cause I just don't understand the reason.... So p.name is the only one so far I've let players define (I'll add the ability later for players to define the other names) when I remove the ability for players to set their own name for p.name then the code works fine and above error does not come.... But with this code in my game it won't let me use p.name in variables....

When I strip the below code out of the game then it lets me use p.name in the variables like you've shown me

Code:
    $ p = renpy.input("What do you want your character's name to be?")
    $ p = p.strip()
    if p == "":
        $ p = "Chloe"
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,201
I've changed the codes now but it still doesn't work
Oops, my bad. !t is for the translation, it's !i that you should use for the interpolation.

idiot me... The flag use the first letter of the associated word...


On a side note:
$firstkiss = f.name + " in the shower after shaving you"
There's no need to add the .name. It's cleaner and more explicit, but Character objects are designed to return the name when represented as a string.


$firstkiss = "In the shower with " + p.name + " after " + f.name + " happened"
AttributeError: 'unicode' object has no attribute 'name'
A well known error.
You assigned another value to p. The way Ren'Py works mean that it will not be seen with the dialog line, but throw an error when used wherever else.


But I've found the cause I just don't understand the reason....
Python:
# You assign a character object to a variable named "p"
define p = Character( "Chloe", [...] )

label whatever:
    # Then you assign something else to the same variable named "p"
    $ p = renpy.input("What do you want your character's name to be?")
    $ p = p.strip()
    if p == "":
        $ p = "Chloe"
It should be:
Python:
define p = Character( "[pName]", [...] )

label whatever:
    $ pName = renpy.input("What do you want your character's name to be?").strip()
    if pName == "":
        $ pName = "Chloe"
 
  • Heart
Reactions: Innocent Chloe

Innocent Chloe

Active Member
Jul 23, 2017
549
902
Python:
# You assign a character object to a variable named "p"
define p = Character( "Chloe", [...] )

label whatever:
    # Then you assign something else to the same variable named "p"
    $ p = renpy.input("What do you want your character's name to be?")
    $ p = p.strip()
    if p == "":
        $ p = "Chloe"
It should be:
Python:
define p = Character( "[pName]", [...] )

label whatever:
    $ pName = renpy.input("What do you want your character's name to be?").strip()
    if pName == "":
        $ pName = "Chloe"
Awesome! It works now! ...and I see as well I need to change my keyboard macros and swap the codes to use [f] [p] [characterX] etc.... instead of the way I've been doing with "%(f)s"

I guess %(f)s is an older or more complicated way to achieve the same? I learnt it from a YouTube guide on Renpy lol...


Everything works now (except stats screen but I understood your advice on that and am still working on fixing it based on what you've said, I might move it to a new stats screen so I can give the text more room or something)

So the code now looks like this;
Code:
$firstkiss = "[f] in the shower after shaving you"
Code:
vbox:
                spacing 10
                text "[virgin]" size 40
                text "[firstkiss!i]" size 40
                text "[firstoral!i]" size 40
                text "[firstsex!i]" size 40
                text "[firstanal!i]" size 40
                text "[beauty]" size 40
                text "[corruption]" size 40
                text "[innocence]" size 40
And the end result in stat screen;
You don't have permission to view the spoiler content. Log in or register now.

I've also tested already with different character names including p and it all works flawlessly

I do have one issue left at the moment.... the strip isn't working unless that's simply wrong code I've put?

So this is how it looks now;
Code:
    $ pName = renpy.input("What do you want your character's name to be?").strip()
    if pName == "":
        $ pName = "Chloe"
But if I, as the player put extra spaces it doesn't strip them
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
Donor
Respected User
Jun 10, 2017
10,963
16,201
I guess %(f)s is an older or more complicated way to achieve the same? I learnt it from a YouTube guide on Renpy lol...
It's a really old way to do it, yes.

It's the problem with Ren'Py guides and tutorials, they tend to be all outdated. Like so far Ren'Py have a great backward compatibility, it past unseen, but it also sometimes deprives you of some useful novelties.


I've also tested already with different character names including p and it all works flawlessly
To be safe you should probably limit the number of letters possible for the different names. This will help define the length of the screen ; format it for a name that have the maximum number of letters, and you will be sure that it will always works.

Among its many parameters, have one named "length" that is made for this. You may also be interested by the "default" one.
Code:
   $ pName = renpy.input("What do you want your character's name to be?", default="Chloe", length=20 ).strip()
I used a length of 20, but it can possibly be a bit less. This said, I don't recommend a length below 15 letters.


[...] the strip isn't working unless that's simply wrong code I've put?
Seen your example, you misunderstood what strip do. It only remove white characters (including space) if they are at the start or the end of the string. " abc " would then become "abc", but "abc def" will stay as it.

This being said, I do not recommend you to remove space in the middle of the name. Assuming that "-" will be the only separator for composed names isn't a good idea. To some limits you should keep as much freedom as possible to the player when it come to the choices for the names.
 
  • Heart
Reactions: Innocent Chloe

Innocent Chloe

Active Member
Jul 23, 2017
549
902
To be safe you should probably limit the number of letters possible for the different names. This will help define the length of the screen ; format it for a name that have the maximum number of letters, and you will be sure that it will always works.

Among its many parameters, have one named "length" that is made for this. You may also be interested by the "default" one.
Code:
   $ pName = renpy.input("What do you want your character's name to be?", default="Chloe", length=20 ).strip()
I used a length of 20, but it can possibly be a bit less. This said, I don't recommend a length below 15 letters.
Ah this is a great idea!!! I'll add it in at 20 for now and then can work out later the right limit to see what dialogue and journal line limits I need to enforce

I take it that in the new format you've posted above I no longer need these strings, as the default is now included in the first line?
Code:
    if pName == "":
        $ pName = "Chloe"

Seen your example, you misunderstood what strip do. It only remove white characters (including space) if they are at the start or the end of the string. " abc " would then become "abc", but "abc def" will stay as it.

This being said, I do not recommend you to remove space in the middle of the name. Assuming that "-" will be the only separator for composed names isn't a good idea. To some limits you should keep as much freedom as possible to the player when it come to the choices for the names.
Yeah I was thinking it would work the same way trim() does on Excel that if you have double or more spaces between letters that it removes them leaving only a single space

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
Donor
Respected User
Jun 10, 2017
10,963
16,201
I take it that in the new format you've posted above I no longer need these strings, as the default is now included in the first line?
Code:
    if pName == "":
        $ pName = "Chloe"
No, the value can still be empty, so you still need this part ; I just don't copied it.
The difference is that now the default value will be directly shown to the player. I find it better, than the usual "if you let it blank, the name will be 'Chloe'".