[SOLVED] Adding text input to character creation screen

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
DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

[SOLVED] Adding text input to character creation screen

#1 Post by DoubleProlix »

So far my intro asks the player for their first and last name, and then calls the character creation screen where they select other options. What I'd like to do is simplify things so that the character creation screen is a one-stop shop for all this info.

Current code:

Code: Select all

    vbox:
        #label "Character Select"
        null height (4 * gui.pref_spacing)
        hbox:
            null width 300
            box_wrap True

            imagebutton:
                ypos 70
                idle "button leftarrow"
                hover "button leftarrow active"
                action [If (gender == 'male', true = [SetVariable("gender",'female')], false=[SetVariable("gender",'male')])]
            null width (4 * gui.pref_spacing)
                
                
            if gender == 'male':
                    add "ico brick male profile" size (300, 300)
            else:
                    add "ico brick female profile" size (300, 300)
            null width (4 * gui.pref_spacing)
            imagebutton:
                    ypos 70
                    idle "button rightarrow"
                    hover "button rightarrow active"
                    action [If (gender == 'male', true = [SetVariable("gender",'female')], false=[SetVariable("gender",'male')])]
    
        hbox:
                box_wrap True
                null width 640
                vbox:
                    null height (4 * gui.pref_spacing) 
                    imagebutton:
                        idle "button ok"
                        action Return()
Looks like this:

Image

So I want some text fields up top. Something like

First Name: [box into which text can be added] -> goes into firstName when user hits ok
Last Name: [box into which text can be added] -> goes into surName when user hits ok

I'd like the boxes to be visible to the player, to make it more obvious that they have to enter text there, rather than just a cursor.
Last edited by DoubleProlix on Fri May 11, 2018 5:06 pm, edited 1 time in total.
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding text input to character creation screen

#2 Post by kivik »

You can do this with screen's input:

https://www.renpy.org/doc/html/screens.html#input

Annoyingly there isn't an example with the values, so this is how you do it:

Code: Select all

input value VariableInputValue('firstName', returnable=True)
input value VariableInputValue('surName', returnable=True)
I'd suggest you put it inside a frame with background to show that it's an input field. You may also want to create a blinking cursor:

Code: Select all

image caret:
    "gui/caret.png" # use your own image
    linear 0.5 alpha 1.0
    linear 0.5 alpha 0.0
    repeat

init:
    $ style.input.caret = "caret"

DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

Re: Adding text input to character creation screen

#3 Post by DoubleProlix »

Okay, I like this so far:

Image

But while I can enter text in the top "First Name" field, I can't seem to switch over to the second input. Clicking on the box does nothing, tab won't do it, etc.
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Adding text input to character creation screen

#4 Post by Imperf3kt »

I found that only one field can be used on a screen. I found a way around this last night, but its not optimal - it involves hiding the input field until you click a button.

Example:
(sorry about it being just an image, I don't have access to the code I used at the moment)
https://i.imgur.com/DOLRYUb.png

You can try it for yourself here:
Rock Paper Scissors 0.2.5

Note: the passwords are currently all just
1.048596
Last edited by Imperf3kt on Wed May 09, 2018 5:29 pm, edited 3 times in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding text input to character creation screen

#5 Post by kivik »

Oh interesting... maybe you can only have one input per screen as it takes over your keyboard, I just had a play and I can't figure it out.

Here's my way around the problem, use a screen variable to determine what you're inputting, and have a textbutton set that variable so that your screen either displays the firstname input or the surname input:

You'll want to create a style for the textbutton to match the input if you're a bit OCD:

Code: Select all

default firstName = "firstname"
default surName = "surname"

screen test:
    default input_name = ""
    frame:
        xalign 0.5
        yalign 0.5
        xsize 400
        ysize 400
        vbox:
            frame:
                background "#444"
                if input_name == "fn":
                    input value VariableInputValue("firstName")
                else:
                    textbutton firstName action(SetScreenVariable("input_name", "fn"))
            frame:
                background "#444"
                if input_name == "sn":
                    input value VariableInputValue("surName")
                else:
                    textbutton surName action(SetScreenVariable("input_name", "sn"))


label start:
    call screen test
Image

DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

Re: Adding text input to character creation screen

#6 Post by DoubleProlix »

I dig it! Don't suppose there's a way to tweak it so that the player can click on anywhere in the frame and not just the text itself?

Image

As is, if I click on the frame to the right of "Hiro" or "Protagonist" (default name), nothing happens... I have to click on the text itself. Can I somehow "extend" the button to the end of the frame, perhaps?
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io


kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding text input to character creation screen

#8 Post by kivik »

You can extend that in theory but you'll have to creating padding to line it up properly. It may be a bit fiddly to do but I don't see why it won't work so long as your button doesn't have a background.

Also, if you set the screen variable to "firstname" at the start of the screen, it'll default to the firstname field, and surname for the surname one. You may want to do that just to indicate player can start typing straight the way.

DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

Re: Adding text input to character creation screen

#9 Post by DoubleProlix »

Something like "Padding = (frame's width) - (my width)" would work. The frame's width is a known quantity, but how do I get the button's current width?
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding text input to character creation screen

#10 Post by kivik »

You may be better off doing an xfill True, not sure how your screen is setup but it stretches the element to the width of the parent element. Then apply xpos to the text inside the textbutton to line it up, I think that'd be text_xpos inside the textbutton.

DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

Re: Adding text input to character creation screen

#11 Post by DoubleProlix »

Well, here's what I have:

Code: Select all

hbox:
            box_wrap True
            null width 515
            vbox:

                label "First Name:"
                frame:
                    xsize 300
                    if input_name == "fn":
                        input value VariableInputValue("firstname")
                    else:
                        textbutton firstname action(SetScreenVariable("input_name", "fn"))
                label "Surname:"
                frame:
                    xsize 300
                    if input_name == "sn":
                        input value VariableInputValue("surname")
                    else:
                        textbutton surname action(SetScreenVariable("input_name", "sn"))
Would I put xfill True at the end of the input statements? or the textbutton? Neither seems to work.
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io

DoubleProlix
Regular
Posts: 33
Joined: Thu Oct 19, 2017 8:04 pm
Contact:

Re: Adding text input to character creation screen

#12 Post by DoubleProlix »

Nevermind, I got it to work with textbutton firstname xfill True action(SetScreenVariable("input_name", "fn"))

Thanks for all your help!
Current Project: Thaumarotica - an occult erotic thriller
SubscribeStar - Patreon - Itch.io

Post Reply

Who is online

Users browsing this forum: No registered users