Ren'Py Script helf for Playername

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
Hi guys,

I hope you can help me.
I want to set the Playername (it already works)

These are my lines:

$ playerName = renpy.input("What's your name? (If you don't enter anything, your name will default to Jonas)")
$ playerName = playerName.strip()
if not playerName:
$ playerName = "Jonas"

"Hello [ThePlayer]."

1st -- I want the default Playername shown in the input prompt. (Jonas)
2nd -- I have 2 Languages ingame (English and German) how can I show it in English and if the german is selected shoe it in German.

But please I need examples with my lines. My english is not very good to understand all.

Thanks for your help.
 

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,671
15,504
Hey, for the first one you need to add default=u'' to renpy.input, e.g.
Python:
$ playerName = renpy.input("What's your name? (If you don't enter anything, your name will default to Jonas)", default=u"Jonas")
$ playerName = playerName.strip()
 
  • Like
Reactions: Blackthunder_vn

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
(y) Thanks this one works.

Can I add an blinking cursor to it? I want the Player to see that they can input an other name.
 
  • Like
Reactions: LightmanP

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
Hey, for the first one you need to add default=u'' to renpy.input, [...]
And for the second, since it's a native Ren'py function, it would be surprising that the "what's your name[...]" string do not appear appear in the translation file.
 
  • Like
Reactions: Blackthunder_vn

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,671
15,504
(y) Thanks this one works.

Can I add an blinking cursor to it? I want the Player to see that they can input an other name.
You're welcome. For a blinking cursor you'd need to have an image of a cursor that you want and then do something like this:
Python:
image cursor:
    "caret.png"
    linear 1.0 alpha 1.0
    linear 1.0 alpha 0.0
    repeat
    
style input:
    caret "cursor"
 
  • Like
Reactions: Blackthunder_vn

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
anne O'nymous it isn't in the translation file. Since it is in the script.rpy it should be in script.rpy--game\tl\deutsch -- I'm right?

Then it should be between this 2 transtalions:

# game/script.rpy:17
translate deutsch start_5740d52e:

# blackthunder "Let's start with that."
blackthunder "Lasst uns damit beginnen."

# game/script.rpy:30
translate deutsch PlyNam_0dce2227:

# "Hello [ThePlayer]."
"Hallo [ThePlayer]."

but there is nothing.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
What I would do...

Python:
default mc_name  = "Unnamed"
define std_mc_name = _("Jonas")

define mc = Character("[mc_name]")

label start:

    scene black with fade

    $ mc_name = renpy.input(_("What is your name? {i}(Press ENTER for '[std_mc_name]'){/i}"))
    $ mc_name = mc_name.strip() or std_mc_name

    "Hello [mc]."

    return

is effectively... this string needs translation too.

We use define for values that never change while the game is running.
We use default for values that the player can change either directly or indirectly (and therefore need to be stored in the save file).

I personally don't like renpy.input( [...], default="Value") - because I change my character name for all games that allow it... and using , default="Something" means I need to erase the old name before I can type my new one.

I use mc for the "main character" Character() object.
I use mc_name for the variable that stores the name used by mc.
Then finally, I use std_mc_name as a constant that stores the "standard main character name".

Edit: btw... You've mixed variables playerName and ThePlayer. Unless ThePlayer is your Character(), in which case, it's probably fine.

Edit2: Added
_() to the RenPy input string too. Oops, I forgot it.
 
Last edited:

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
79flavors

it works fine this way:

$ playerName = renpy.input("What's your name?...", default=u"Jonas" )
$ playerName = playerName.strip()
if not playerName:
$ playerName = "Jonas"

"Hello [ThePlayer]."

and this is the variable:

label Variables:
$ playerNameinput = "[playerName]"


My big problem now is (2nd), that ("What's your name?...") isn't in the translation so it is in german the same english line.
 

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
I have changed all playerName to ThePlayer it works fine.

Ok you have an Point in the shown Char name. Have changed it back. <but now new Players dont see that they can change the Name> my thinking

The translation isn't there as before for this line.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
it works fine this way:

Technically, I suppose so. My way's better though. :devilish:

My big problem now is (2nd), that ("What's your name?...") isn't in the translation so it is in german the same english line.

Yeah, I missed the from the renpy.input too. I knew it should be there, I just don't do translations very often. Edited my example to correct that.
 
  • Like
Reactions: Blackthunder_vn

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
Thank you very much it all works as it should.

I know your way is the better one, but if I change it to MC I have to change the complete script to it everywere ThePlayer is.
Thats not the big problem.
The problem is the translation, I have to make a new translation (in RenPy no problem too.) but the i have to copy every single line for it self on its right place. 7500 lines.

I don't want to, so it works. And I dont have to change anything, without 4 lines.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Easy?
No.

But it was recently discussed here, with a few different sources for alternatives.

The last time I touched anything like that, I used the code from College Kings then heavily modified it. The fundamentals are pretty simple... some classes to store the messages and/or the contacts and a screen or two to show them. If you know how to do it, it's easy - but if you knew how to do it... you wouldn't be asking.

A generic phone system is on my to-do list... and if RL continues how it has been recently, I should get to it shortly after the heat death of the entire universe.
 
  • Like
Reactions: Blackthunder_vn

moskyx

Forum Fanatic
Jun 17, 2019
4,005
12,960
Surprising :/ But 79flavors gave you the workaround.
Menu choices are the only "non dialogue" strings that will appear automatically in the translation file. Character names, prompts like the one that originated this thread, tooltips, text variables (defined as items in lists), textbuttons... none of those strings apppear unless you edit the original script to wrap them with _().

The other option is to write the translation command manually. In the example given by OP, it could have been solved writing this in any script:
Python:
translate german strings:
    old "What's your name? (If you don't enter anything, your name will default to Jonas)"
    new "the same but in German"
But in that case you need to be very careful to not include a typo in the old string, otherwise the translation won't work. So using the _() is always the way to go... unless you can't find where the heck that untranslatable string is in the scripts.

Having to check every single script to find those strings and wrap them with _() is incredibly annoying and probably the most time-consuming task for translators (especially in complex games), not to mention the frustration beginners feel when they realize they can't find those lines anywhere in the translation scripts and don't know why. It's a clear flaw in Ren'Py's code
 
  • Like
Reactions: Blackthunder_vn

Blackthunder_vn

Active Member
Game Developer
Jan 31, 2020
582
1,467
So it all works. But....

The defined Playername has an other color (is shown as standard Renpy color light blue) and I chan't change it.

The Variable:
label Variables:
$ playerNameinput = "[ThePlayer]"

The Change of the Playername:
$ ThePlayer = renpy.input(_("What's your name?... {i} (Press ENTER for 'Jonas' or type in your choice.) {/i}"))
$ ThePlayer = ThePlayer.strip()
if not ThePlayer:
$ ThePlayer = "Jonas"

"Hello [ThePlayer]."

The definitions for The Player:

define ThePlayer = Character("[ThePlayer]", what_font="Chianti Bold Win95BT.ttf", color="#323ee3") shown as standard light blue (color of my renpygame)

define ThePlayer_t_en = Character("{i}[ThePlayer] *thinks*{/i}", what_font="Chianti Bold Win95BT.ttf", color="#323ee3") shown as defined

Why cant I change the color?

Thanks for your help.
Blackthunder
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
So it all works. But....

[...]

Why cant I change the color?

The issue is because you're initially creating a Character() and then overwriting it with a string object. String objects have none of the parameters/properties necessary for the formatting your want.

So you start off with define ThePlayer = Character(). That's fine.
But later, you do $ ThePlayer = renpy.input().

renpy.input() returns a string. So now ThePlayer is now a string and not a Character().

What you need to do is separate the character object from the variable that contains the name.

Using your own code as the basis...
Edit: This code is a good example for other people, but won't solve YOUR problem. I've written something specific to your project further down...

Python:
define ThePlayer = Character("[player_name]",  what_font="Chianti Bold Win95BT.ttf", color="#323ee3")
define ThePlayer_t = Character("[player_name]",  what_font="Chianti Bold Win95BT.ttf", color="#323ee3", what_prefix="{i}(", what_suffix="){/i}", who_prefix="{i}", who_suffix="{/i}")

default player_name = "Unnamed"

label start:

    scene black with fade

    $ player_name = renpy.input(_("What's your name?... {i} (Press ENTER for 'Jonas' or type in your choice.) {/i}"))
    $ player_name = player_name.strip()
    if not player_name :
        $ player_name = "Jonas"

    "Hello [ThePlayer]."

    return

I've tweaked your "character thinking" definition a bit, to make the text shown when thinking italic and also wrap it in parenthesis (pretty normal for VNs).

Now, the new variable player_name stores the name of the main character and the two Character() objects use string substitution to use that variable whenever it's displayed.

Now the problem...

You're going to have to delete all your current save files.
Oh crap. You've already released version 0.0.15.2 of your game... Downloading now to check it.

While it downloads, let me just explain the problem...

Any saves files out there have a variable called ThePlayer in them. That variable, in that version of the game, is a string. When you load the save file, whatever you've got coded will be overwritten with the variable stored in the save file. Essentially, it'll reset your Character() object - as I've described above.

I can only see one reasonable answer, but I'm not sure you're going to like it.
Let me also adapt my answer to include your need for a German translation...

Python:
define mc = Character("[ThePlayer]",  what_font="Chianti Bold Win95BT.ttf", color="#323ee3")
define mc_t = Character("[ThePlayer]",  what_font="Chianti Bold Win95BT.ttf", color="#323ee3", what_prefix="{i}(", what_suffix="){/i}", who_prefix="{i}", who_suffix="{/i}")

default ThePlayer = "Unnamed"

label start:

    scene black with fade

    $ ThePlayer = renpy.input(_("What's your name?... {i} (Press ENTER for 'Jonas' or type in your choice.) {/i}"))
    $ ThePlayer = ThePlayer.strip()
    if not ThePlayer :
        $ ThePlayer = _("Jonas")

    "Hello [mc]."

    return

Then go into your script editor and do a "Change ALL 'ThePlayer' to 'mc'."
If you're using Atom, you would...
  • Press <CTRL+SHIFT+F> (Find and Replace in all files).
  • Change "Find in Project" to ThePlayer
  • Change "Replace in Project" to mc
  • Change "File/Directory Pattern" to *.rpy
  • Activate the button on the right side with Aa in it, to make the search/replace case sensitive.
  • Click [Replace All]

Next you're going to need to fix the couple of places that have been changed to mc but still need to say ThePlayer.

In my example, that would be the default line that initializes the main character name to be "Unnamed". The Character() definitions which need the [mc] changing to [ThePlayer] and the section of code that does the renpy.input of the name.

Then you're going to need to get into the habit of typing "mc" instead of "ThePlayer".
Honestly, it can be anything EXCEPT "ThePlayer", since ThePlayer is a string variable separate from the Character() definition. I've used "mc" because it is the common identifier used in VNs and it's quick to type.

By doing it this way... even though the variable ThePlayer was incorrectly used in the original version of the game... it can still be used for future versions without breaking anything. So when a player loads an old save file... everything will still work.

Plan-B: Use the solution I suggested first. Then go into the options.rpy file and change the line that start define config.save_directory = to something else. That will force future save files to be stored somewhere else and you'll need to tell existing players that old save files are not compatible with the current version.

Of course, this is all just my opinion. Someone else might come up with an alternative solution. But the fact that you've already released a version of your game with this code in it... makes it awkward to fix.
 

moskyx

Forum Fanatic
Jun 17, 2019
4,005
12,960
Another problem when replacing ThePlayer with mc is that now he would need to rewrite absolutely every single line in the German translation file (at least those with the old ThePlayer as sayer), something he already said he was not willing to do
Thank you very much it all works as it should.

I know your way is the better one, but if I change it to MC I have to change the complete script to it everywere ThePlayer is.
Thats not the big problem.
The problem is the translation, I have to make a new translation (in RenPy no problem too.) but the i have to copy every single line for it self on its right place. 7500 lines.

I don't want to, so it works. And I dont have to change anything, without 4 lines.
So... bye bye old saves, I guess
 
  • Like
Reactions: Blackthunder_vn

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Another problem when replacing ThePlayer with mc is that now he would need to rewrite absolutely every single line in the German translation file (at least those with the old ThePlayer as sayer)

I'm not so sure.
The translation files are also called *.rpy so it might be fine

It's something I'd do myself. But I understand his hesitancy.