How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected? [SOLVED]

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
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected? [SOLVED]

#1 Post by Obscura »

I have a screen containing multiple, draggable input boxes. The problem is when I am filling out one box, the contents of the other box momentarily disappears.

Code: Select all

screen text_input_screen():
    
    frame:
        xpos 250
        ypos 300
        
        draggroup:

            drag:
                xpos 300 ypos 300
                default screenvar = False
                droppable False
                imagemap:
                    ground "background.png"
                    idle "idle.png"
                    hover "hover.png"
                    selected_idle "hover.png"

                    hotspot (150,140,475,200) action SetScreenVariable("screenvar",True), SetScreenVariable("screenvar1",False)
                    if screenvar == True:
                        input default firstname pos(200,165) changed name_func

            drag:
                vbox:
                    ypos 400
                    default screenvar1 = False
                    imagemap:
                        ground "background.png"
                        idle "idle.png"
                        hover "hover.png"
                        selected_idle "hover.png"

                        hotspot (150,140,475,200) action SetScreenVariable("screenvar1",True), SetScreenVariable("screenvar",False)
                        
                        if screenvar1 == True:
                            input default lastname pos(200,165) changed lastname_func

        textbutton "Done":
            xalign .5
            action Return()
            
init python:
    def name_func(newstring):
        store.firstname = newstring

        
    def lastname_func(newstring):
        store.lastname = newstring

init:
    default firstname = ""
    default lastname = ""
            
            
start:
     "And so it begins."
     call screen text_input_screen()
     
            
(There are more boxes than this, but the code should give you and idea of what's happening.)
The disappearing act is because of SetScreenVariable("screenvar",False) or SetScreenVariable("screenvar1",False) when the other box is clicked. The problem is that if I DON'T include this piece of code, I can no longer toggle back to the first box. I seem to be stuck in the second box perpetually.

Is there a way to either toggle freely back and forth between the boxes, or to keep the input text inside the one box when typing into the other?

Thanks!
Last edited by Obscura on Thu Feb 07, 2019 2:02 am, edited 1 time in total.
Coming Out On Top - An Adult Gay Dating Sim
website

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#2 Post by Obscura »

I edited this post--which was originally about how to double click and edit a draggable button, but it seems double-clicking gets complicated, at least according to this thread, so I'm approaching the issue from a different angle but have run into the questions above.
Coming Out On Top - An Adult Gay Dating Sim
website

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

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#3 Post by philat »

Well, you're hiding the input itself when you select the other box. Why do you need the hotspot/screenvar combo?

ETA: Like, specifically, I am asking why you're saying that not including it prevents you from editing the other box. Having two boxes with just the following seems to be working fine. You have to drag it a little to 'select' the input, but you can edit both boxes.

Code: Select all

            drag:
                droppable False
                imagemap:
                    ground "background.png"
                    idle "idle.png"
                    hover "hover.png"
                    selected_idle "hover.png"
                    input default firstname changed name_func

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#4 Post by Obscura »

Thanks for the simplified code.
The issue I'm having is:

Type in box 1, you'll be able to input fine.
Then type in box 2, you'll be able to input fine.
If you GO BACK to box 1 to edit it (because the player may want to edit the first box before submitting both), you cannot click into it unless you click several times on the inputted text (may be because you have to "touch" the letters with the cursor?) I'm looking for some way of allowing the player to go back and forth between boxes without having to be quite so exacting with the clicks.
Coming Out On Top - An Adult Gay Dating Sim
website

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

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#5 Post by philat »

Like I said, it's not that you have to click multiple times -- you have to drag it. I mean, I guess if you're really set on this the obvious answer is to have an else text firstname in there, but I confess I don't really see the use case for draggable editable text areas for taking the player's name.

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#6 Post by Obscura »

Ah, understood. I was just using the firstname and lastname since it was the example used from this thread: viewtopic.php?f=51&t=38080 from Namastaii.

These would have a different purpose in my game. I may just use Namastaii's alternative code to do this, which doesn't have the hotspots but would probably be fine.
Coming Out On Top - An Adult Gay Dating Sim
website

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

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#7 Post by philat »

Well, okay, that makes more sense (re: different use). I mean, like I said, throwing an else text firstname in there after the if screenvar stuff works fine... it's probably not ideal, but it's the path of least changes made at this moment. *shrug*

User avatar
Obscura
Eileen-Class Veteran
Posts: 1431
Joined: Fri Mar 09, 2012 6:58 pm
Projects: Coming Out On Top
Location: United States
Contact:

Re: How to Prevent Input Box A from Losing Its Contents when Input Box B is Selected?

#8 Post by Obscura »

Actually, that will work perfectly, now that I'm testing this. I couldn't figure out the syntax for some reason. Thank you!
Coming Out On Top - An Adult Gay Dating Sim
website

Post Reply

Who is online

Users browsing this forum: Bing [Bot]