[Solved] Make it so you can't put a space when writing your name.

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.
Post Reply
Message
Author
User avatar
simba975
Newbie
Posts: 22
Joined: Sun Jul 23, 2023 12:05 pm
Contact:

[Solved] Make it so you can't put a space when writing your name.

#1 Post by simba975 »

I'm using this for the player to write their name:

Code: Select all

screen name_screen():
    window:
        text "What's your name?" xalign 0.5 yalign 0.1
        input default "" xalign 0.5 yalign 0.25 length 10

Code: Select all

    label yourName:
        scene
        show black onlayer bg

        call screen name_screen with dissolve
        $ player_name = _return
        $ player_name = player_name.strip()
        $ player_name = player_name.lower()
        $ player_name = player_name.title()
This works well, however, when the player just presses space they are able to just have an empty name. How can I prevent players from entering the name after just spaces?
Last edited by simba975 on Sat Feb 10, 2024 5:34 am, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Make it so you can't put a space when writing your name.

#2 Post by philat »

You can limit the characters allowed in input using the allow keyword. https://www.renpy.org/doc/html/input.html

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Make it so you can't put a space when writing your name.

#3 Post by m_from_space »

simba975 wrote: Mon Jan 22, 2024 5:51 pm How can I prevent players from entering the name after just spaces?
Just test if the player entered a valid name (and not an empty string).

Code: Select all

label yourName:
    scene
    show black onlayer bg
    call screen name_screen with dissolve
    $ player_name = _return
    $ player_name = player_name.strip()
    $ player_name = player_name.lower()
    $ player_name = player_name.title()
    if not player_name:
        "Please enter a valid name!"
        jump yourName
    jump elsewhere

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Kia