Entering the character's name on Renpy

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 721
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Entering the character's name on Renpy

#1 Post by Andredron »

1)Plain

Code: Select all

define g = Character("[name]")

label start:
    python:
        name = renpy.input(_("What's your name?"))
    name = name.strip() or __("Zhora!t")
    "hello [name]"
    g "Hello to you too"
- define g = Character("[name]") - we write the name of the character with the variable "[name]"

- python: - we can use python and $

- name = renpy.input(_("What's your name?")) - we highlight the question, and the variable name will have this value when entering text

- name = name.strip() or __("Zhora!t") - insurance in case the user has not entered anything, then the name will be automatically selected by Zhora!t – so that the variable is displayed in the translation

- "hello [name]" - is the text of the dialogue, in square brackets they write a variable that needs to be reflected in the text (name, number of money, coins left.... in the text of the dialogue).

This method has a lot of disadvantages:
1) Unlimited number of characters to enter. I.e., enter 60 characters and continue the text, you will see an error. We have not introduced a limit on the min and max number of characters
2) If a Chinese person enters a name in his native language, then instead of hieroglyphs he will have a quaker, due to the fact that the font of the dialogue does not support his language. And we have not introduced a restriction on the input language.
3) Not a beautiful and intuitive input interface for beginners who are playing short stories for the first time.

2) A little more complicated

Code: Select all

define hero = DynamicCharacter(u'mc', image="hero", ctc=anim.Blink("arrow.png"))

label start:
    $ mc = renpy.input("PLEASE GIVE YOUR CHARACTER A NAME. The number of characters is 2-10.", default =_("Zorro"), allow=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZйцукенгшщзхъэждлорпавыфячсмитьбюЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ" , length=10)
    $ mc = mc.strip()
    
    if len(mc) < 2:
        "You must use at least 2 letters"
        jump start
        
    window show
    hero smiling  "[mc]...I haven't seen you anywhere..."
    
    menu:
        "Do you want to be [mc]?"
        "No":
            jump name_vibor2
        "Yes":
            pass
            
    hero smiling "Yes, I'm new..."
allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZйцукенгшщзхъэждлорпавыфячсмитьбюЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ" -
We have prescribed what can be entered into the project (If letters, then large and small - otherwise it will not accept), as you can see there are no symbols or icons here – only letters of Russian and English

length=10 - The maximum number of characters we can enter

if len(mc) < 2:
"You must use at least 2 letters"
jump start

The condition if less than 2 characters were entered from the keyboard and then moved back to the selection window.

3) Screen Text Input
This text input works by hovering over the box and then typing while your cursor is still over the box. Then you can move your cursor to the next box to begin typing there. You don't need to click. Though if anyone knows the specific code to make it so you click instead of hover, please also let me know about that
viewtopic.php?f=51&t=38080#p412159


4) Entering text directly into Ren'Py without using modal dialogs.

Entering text in Ren'Py basically involves displaying the input screen and getting the results (in the manual, we enter data from a text window). However, there may be times when you want to enter text directly without opening a dialog box. A script was presented here that allows you to enter data as is.

viewtopic.php?f=51&t=31289

5) WE REGISTER THE NAME AND SURNAME OF THE CHARACTER

Code: Select all

init python:
     first_name = 'Unnamed!t'
     last_name = ''
     input_first_name = 'Ivan!t'
     input_last_name = 'Ivanov!t'
     min_name_len = 2
     max_name_len = 10
     nameless = Character("'{0} {1}'.format(first_name,last_name).strip()", dynamic=True)
    
label start:
     scene bg timelessness
     nameless "It's time to choose a name for yourself. A name will not choose itself."
label first_name_input:
     call screen screen_name_input("Enter name:",'input_first_name')
     if _return == '_b_enter':
         if len(input_first_name) < min_name_len:
             "The name is too short!"
             jump first_name_input
         else:
             $first_name = input_first_name
             nameless "My name will be [first_name]"
     elif _return == '_b_cancle':
         nameless "I'll leave everything as it is..."

label last_name_input:
     call screen screen_name_input("Enter last name:",'input_last_name')
     if _return == '_b_enter':
         if len(input_last_name) < min_name_len:
             "The last name is too short!"
             jump last_name_input
         else:
             $last_name = input_last_name
             nameless "My last name will be [last_name]"
     elif _return == '_b_cancle':
         nameless "I'll leave everything as it is..."
     jump continued
     
screen screen_name_input(t,v):
     key 'input_enter' action Return('_b_enter')
     key 'K_ESCAPE' action Return('_b_cancle')
     frame:
         align(0.5,0.5)
         xsize 300
         vbox:
             text "[t]":
                 xalign 0.5
             text "(from [min_name_len] to [max_name_len] characters)":
                 xalign 0.5
             input:
                 xalign 0.5
                 value VariableInputValue(v)
                 length max_name_len
                 allow "YTSUKENGSHSHCHZHIFYVAPROLJEYACHSMMITYutsukengshschzhfyvaproljayachsmithbyQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"
             hbox:
                 xfill True
                 textbutton "Cancel":
                     action Return('_b_cancle')
                     xalign 0.5
                 textbutton "Enter":
                     action Return('_b_enter')
                     xalign 0.5

label continued:
     nameless "My name will be [first_name]"
     nameless "My last name will be [last_name]"
     nameless "My name is [nameless]"
6)How to register a dynamically changing name

Code: Select all

define m = DynamicCharacter("hero_name") # Initially, we do not write down a specific character name.
label start:
     $ hero_name = "???!t " # Variable where the character name is "???"
     m "Who am I?"
     $ hero_name = u"Hero!t " # Variable where the character appears with a specific name
     m "So I am [hero_name]!!!"
     $ hero_name = "???!t " # Variable where the character name is again "???"
     m "No?"
     $ hero_name = u"Villain!t " # Variable where the character appears with a specific name
     m "I guess I'm [hero_name]!"
7) How to register a pc user name

Code: Select all

init python:
    import os
    player = os.environ.get( 'USERNAME', 
                 os.environ.get( 'USER', 
                 os.environ.get( 'LNAME', 
                 os.environ.get( 'LOGNAME', 'Player' ))))
 
label start:
    "Hello there, [player]."

8) Retro on-screen keyboard
viewtopic.php?f=51&t=25972

9) About choosing names and caps/case sensitive
viewtopic.php?p=565832#p565832

10) consol
viewtopic.php?p=565223#p565223

11)Remove Blinking Text Cursor in Name Input
viewtopic.php?p=564292#p564292

12) Input MC name that filters NPC names! + extra nifty features (Ren'Py 7.4.2)
viewtopic.php?t=61374

13) Create a profile, with the ability to delete

viewtopic.php?p=558993

14) name generator
viewtopic.php?p=557270

viewtopic.php?t=68177

Code: Select all

define mc = DynamicCharacter("mc_name")
default names = ["Eisley","Romi","Arianwen","Elvira","Belphoebe","Etol","Aralueni","Morag","Ottoline","Velnor","Euphoria","Envy","Naiad","Hauntice","Malice","Aquina","Sprite","Revelation","Ethereal","Priam"]
default mc_name = ""

init python:
    def generate_random_mc():
        store.mc_name = renpy.random.choice(names)

screen mc_naming:
    vbox:
        hbox:
            text "Character name:" 
            input value VariableInputValue("mc_name") minwidth 150 length 24

        textbutton "Start" action Return() # due to label flow, this falls through to label greeting anyway
        textbutton "Generate" action [SetVariable("mc_name", renpy.random.choice(names))] # given that your function only does one thing, simply using SetVariable directly seems far more efficient
        textbutton "Generate (Function)" action Function(generate_random_mc) # example of using a function if you intend to extend the function further (I really don't see the point of the generator class)

label start:
    call screen mc_naming  

label greeting:
    mc "hello!"
    mc "my name is [mc_name]"
    return
15) entry screen that'll pick a random name for you if you don't input anything
viewtopic.php?p=558708&hilit=random#p558708

16) Change renpy.input color mid-input
viewtopic.php?p=555915

17) Sound effect while typing?
viewtopic.php?p=547597

18) Screen to Track Number of Characters in Renpy.Input
viewtopic.php?p=551274

19) Multiplication
viewtopic.php?p=548414

20) Type out predetermined word when player types
viewtopic.php?p=566690#p566690

21) Converting numerical renpy.input to value
viewtopic.php?p=544236

22) Combined name + pronoun selector screen
viewtopic.php?p=543619

23)Enter ingredient to find 1 or more recipes
viewtopic.php?p=539992

24) Search a word in list
viewtopic.php?p=539364

25) Capitalizing a customised name
viewtopic.php?p=517367

26) exporting .rpy files through Ren'Py or another way
viewtopic.php?p=515924

27) Is it possible for the renpy.input dialogue to be said by a character and not the narrator(buble)
viewtopic.php?p=566723#p566723

Post Reply

Who is online

Users browsing this forum: No registered users