Text input (on screen)

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
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Text input (on screen)

#1 Post by namastaii »

UPDATE: The more up-to-date version of this code can be found here:
viewtopic.php?f=51&t=38080





Before, I was trying to figure out how to put a text input on screen, instead of in the dialogue. I figured I'd share what worked for me, in case you'd like to use it for your visual novels.

Here is a simple example:

Image

This is the exact code for the example above:

Code: Select all

init python:
    def name_func(newstring):
        store.firstname = newstring

        
    def lastname_func(newstring):
        store.lastname = newstring

Code: Select all

screen name_input():
    imagemap:
        ground "gui/clipboard.png"
        hbox xalign 0.6 yalign 0.20:
            text "{color=#000000}First Name:"
            button:
                id "name_input1"
                xysize (250, 25)
                action NullAction()
                add Input(size=30, color="#ff0066", default=firstname, changed=name_func, length=10, button=renpy.get_widget("name_input","name_input1")) yalign 1.0
        hbox xalign 0.6 yalign 0.30:
            text "{color=#000000}Last Name:"
            button:
                id "name_input2"
                xysize (250, 25)
                action NullAction()
                add Input(size=30, color="#ff0066", default=lastname, changed=lastname_func, length=10, button=renpy.get_widget("name_input","name_input2")) yalign 1.0     

        
The first and last name were stored as: [firstname] and [lastname]

It's up to you how you continue from the text input, but it's tested and works. The inputs are saved. I hope this was somewhat helpful.

If you maybe want something like a button to open this screen, you can do this:

Code: Select all

screen name_input_button():
    button xalign 0.3 yalign 0.12:
        text "[firstname]" 
        action ui.callsinnewcontext("name_input_label")
Its a text label that prints the last name you put in for 'firstname'

You could move these around to create something more unique, as well.
Last edited by namastaii on Mon May 02, 2016 5:16 pm, edited 3 times in total.

User avatar
TrailsInTheSky
Regular
Posts: 39
Joined: Thu May 22, 2014 10:27 am
Projects: I'm Not The Perfect Guy For Her
Contact:

Re: Text input (on screen)

#2 Post by TrailsInTheSky »

Thanks alot :D
Mystery creates wonder and wonder is the basis of man's desire to understand.
-Neil Armstrong

Current project: I'm Not The Perfect Guy For Her (Rom.Com.Drama)
https://www.facebook.com/trailsin.thesky.1
http://bestofthebestclassicalpianomusic.tumblr.com
http://blog-trailsinthesky.tumblr.com/

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#3 Post by namastaii »

No problem. If you use it and have any problems, just ask :)

Tentacles
Regular
Posts: 69
Joined: Tue Jul 14, 2009 10:02 pm
Projects: Uploaded Fairy ( Interactive Comic )
Deviantart: otissalmoneus
Github: LWFlouisa
Contact:

Re: Text input (on screen)

#4 Post by Tentacles »

Question: Can this cookbook code be modified somewhat to have text-input be at the bottom of the screen? I was thinking of having visual novels where you type text input instead of traditional choices.

You would still have choices displayed to you, but to actually make a choice you type it out.
I develop horror romance interactive comics. Currently working on my first.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#5 Post by namastaii »

Well, you could re position the numbers and make the boxes appear on every page if that is what you mean. and assign each text box to a value/action to what you need it for.

lovelyinc
Newbie
Posts: 14
Joined: Tue Dec 08, 2015 5:52 pm
Contact:

Re: Text input (on screen)

#6 Post by lovelyinc »

Hi! I have been trying to get this for awhile. How do I get this screen to appear right before the prologue? As in how do I call this screen from the script I guess? (call screen function doesn't work) - also, where would I put my hotspot info? I have the hotspot around the white box so the player clicks the box, allows you to type and then can press enter to continue on with game.

Thank you in advance have been trying to figure this out for ages!

Here is my image map attached -
Attachments
Name_Input.png

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#7 Post by namastaii »

You should be able to open the screen wherever you put 'show screen screennamehere' just place it after your start label or wherever you wanted it to be before your prologue and stuff.

lovelyinc
Newbie
Posts: 14
Joined: Tue Dec 08, 2015 5:52 pm
Contact:

Re: Text input (on screen)

#8 Post by lovelyinc »

namastaii wrote:You should be able to open the screen wherever you put 'show screen screennamehere' just place it after your start label or wherever you wanted it to be before your prologue and stuff.

Thank you! I had misspelled it when calling - my major problem though is the hotspot. I noticed you don't have any hotspots on your image map - I'd like it so that when the player clicks on the white box they can start typing their name - do you know how I would go about coding that?

viewtopic.php?f=8&t=38375 <<< I made a topic for it.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#9 Post by namastaii »

Yes. I included a link to the updated version at the top. but here it is again: viewtopic.php?f=51&t=38080

if you scroll down the post, someone posted an example that should be able to do what you want (the clicking to type in the box)
Though, i haven't tried it.

I don't think you need a hotspot to achive what you're doing. buttons take hover and click actions and I don't think you can put a text input in a hotspot..

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#10 Post by namastaii »

Actually. I think I understand what you mean better. Let me try it out and let you know.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#11 Post by namastaii »

I'm going to upload the file to the other thread but this is basically what I did

The screen:

Code: Select all

screen text_input_screen2():
    default screenvar = False
    imagemap:
        ground "background.png"
        idle "idle.png"
        hover "hover.png"
        selected_idle "hover.png"
        
    
        hotspot (150,140,550,200) action SetScreenVariable("screenvar",True)
        if screenvar == True:
            
            input default "bob" pos(200,165) changed name_func
(I styled the input stuff so it looks nicer)

Code: Select all

init python:
    style.input.caret = "my_caret"
    style.input.size = 60
    style.input.color = "#000"

lovelyinc
Newbie
Posts: 14
Joined: Tue Dec 08, 2015 5:52 pm
Contact:

Re: Text input (on screen)

#12 Post by lovelyinc »

namastaii wrote:I'm going to upload the file to the other thread but this is basically what I did

The screen:

Code: Select all

screen text_input_screen2():
    default screenvar = False
    imagemap:
        ground "background.png"
        idle "idle.png"
        hover "hover.png"
        selected_idle "hover.png"
        
    
        hotspot (150,140,550,200) action SetScreenVariable("screenvar",True)
        if screenvar == True:
            
            input default "bob" pos(200,165) changed name_func
(I styled the input stuff so it looks nicer)

Code: Select all

init python:
    style.input.caret = "my_caret"
    style.input.size = 60
    style.input.color = "#000"

Thank you soooooooooooooo much! This worked perfectly! :D I did need to make a done button with hotspot and action Return() but it stored the name and everything works - thank you again!! <3

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#13 Post by namastaii »

Glad it works^^

lovelyinc
Newbie
Posts: 14
Joined: Tue Dec 08, 2015 5:52 pm
Contact:

Re: Text input (on screen)

#14 Post by lovelyinc »

namastaii wrote:Glad it works^^
Thanks! You may not know this one, but now when I export it to the iphone simulator it doesn't pull up the keyboard when it's time to input the name - where as before when it wasn't an image map as soon as it got to that screen it would pull it up. So there will be no way for people to type /: If you don't know this one I am just going to create a thread!

Thank you for all your help,

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Text input (on screen)

#15 Post by namastaii »

Hmm interesting... I have no idea why it wouldn't bring it up but I don't have any experience with trying it out on phone stuff..

Post Reply

Who is online

Users browsing this forum: No registered users