Require player-inputed text in a later text input?

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
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Require player-inputed text in a later text input?

#1 Post by Offworlder »

What I'm trying to do might be a bit complicated. Basically, I want to simulate an account creation. On one screen, players will input their chosen username and password. Later, they can log into a simulated website using said username/password.

To accomplish this, there are a few specific things I'd like to include for as realistic of an experience as possible.

1. The username and password input will be on the same screen. I haven't come across any way to have multiple available inputs at once.
2. I want players to be able to click the username or password box to switch which input is active. Once clicked, the box image would change to indicate that it's active. Perhaps with a sound effect as well?
3. There needs to be text of a certain length in each box before players can proceed. Otherwise, an error would appear.
4. Lastly, and perhaps most importantly, I'm looking for a way to ensure that if players enter the specific string of text they inputed for their username/password, it will enable them to "log in".

Does anyone have any idea at all how I would go about doing any of this? I'm honestly a bit lost. x_x
All help is tremendously appreciated!

Side Note: I imagine this sounds like it could potentially be an irritating feature for players. I will say that it serves a purpose in the overall narrative, but it won't be something that needs to be done repeatedly.
Last edited by Offworlder on Sun Jul 21, 2019 5:08 am, edited 1 time in total.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Require player-inputed text in a later text input?

#2 Post by Per K Grok »

Offworlder wrote: Sat Jul 20, 2019 8:50 pm What I'm trying to do might be a bit complicated. Basically, I want to simulate an account creation. On one screen, players will input their chosen username and password. Later, they can log into a simulated website using said username/password.

To accomplish this, there are a few specific things I'd like to include for as realistic of an experience as possible.

1. The username and password input will be on the same screen. I haven't come across any way to have multiple available inputs at once.
2. I want players to be able to click the username or password box to switch which input is active. Once clicked, the box image would change to indicate that it's active. Perhaps with a sound effect as well?
3. There needs to be text of a certain length in each box before players can proceed. Otherwise, an error would appear.
4. Lastly, and perhaps most importantly, I'm looking for a way to ensure that if players enter the specific string of text they inputed for their username/password, it will enable them to "log in".

Does anyone have any idea at all how I would go about doing any of this? I'm honestly a bit lost. x_x
All help is tremendously appreciated!

Side Note: I imagine this sounds like it could potentially be an irritating feature for players. I will say that it serves a purpose in the overall narrative, but it won't be something that needs to be done repeatedly.

This is not what you are asking for, but it will do the job.
Maybe there is something in this you will find useful.

Code: Select all


init python:
    def logname_func(newstring):
        store.logname = newstring

    def logPW_func(newstring):
        store.logPW = newstring

default logname=""
default logPW=""


screen login1():
    frame:
        vbox:
            xsize 200
            ysize 100
            text "Enter name and password"
            text "Name:"
            frame:
                xsize 100
                input  changed logname_func length 15
            textbutton "Next" action [Show("login2"), Hide("login1")]

screen login2():
    frame:

        vbox:
            xsize 200
            ysize 100
            text "Password:"
            frame:
                xsize 100
                input changed logPW_func length 15
            textbutton "Login" action Jump("loginLabel")
            textbutton "Back" action [Show("login1"), Hide("login2")]

###############################################################################

label start:

    scene red
    show screen login1

    $ renpy.pause(hard=True)
 
    
label loginLabel:

    if logname=="James Bond" and logPW=="007":
        "Login successful."
    else:
        "Name or password are incorrect."

    hide screen login2
    jump start    
    
    
    



User avatar
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Require player-inputed text in a later text input?

#3 Post by Offworlder »

Per K Grok wrote: Sun Jul 21, 2019 1:43 am This is not what you are asking for, but it will do the job.
Maybe there is something in this you will find useful.
I know you gave a disclaimer right at the beginning, so I certainly won't complain too much!
Part of your code actually does one major thing I was trying to figure out. Specifically, the ability to parse information from two different input boxes when determining whether the player receives an error or can proceed forward. On the flip side, I noticed you have a defined username/password right from the beginning. For story-reasons, it's very important for the player to create their own username/password (perhaps with a similar code as the one that allows a nameable protagonist?). Then, at a later point, they must enter the created username/password into a different input box in order to proceed. Perhaps this would also be similar to the "nameable protagonist" code? I've honestly been having trouble getting it to work, so that might be part of the problem. x_x

The other major thing is having both input boxes on the same screen, where yours are actually on separate screens.
Either way, though, I appreciate your assistance! I think I can work with at least the one part of your code. : )

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Require player-inputed text in a later text input?

#4 Post by Per K Grok »

Offworlder wrote: Sun Jul 21, 2019 2:59 am On the flip side, I noticed you have a defined username/password right from the beginning. For story-reasons, it's very important for the player to create their own username/password (perhaps with a similar code as the one that allows a nameable protagonist?). Then, at a later point, they must enter the created username/password into a different input box in order to proceed. Perhaps this would also be similar to the "nameable protagonist" code?


This will add user chosen username and password.

I don't at this time see a way to avoid using a two screen solution. It is easy to show two inputs at the same time but I have found no way to shift focus between them.

Code: Select all


default IPname=""
default IPpass=""

###############################################################################

label start:

    scene red

    $ IPname=renpy.input("chose username:")
    $ IPpass=renpy.input("Chose password:")


    show screen login1

    $ renpy.pause(hard=True)

label loginLabel:

    if logname==IPname and logPW==IPpass:
        "Login successful."
    else:
        "Name or password are incorrect."

    hide screen login2
    jump start


User avatar
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Require player-inputed text in a later text input?

#5 Post by Offworlder »

Unfortunately, this most recent example isn't quite working. If I use just the code from your second post, it gives me this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 47, in script
    show screen login1
  File "renpy/common/000statements.rpy", line 510, in execute_show_screen
    renpy.show_screen(name, *args, **kwargs)
Exception: Screen login1 is not known.
If I use the second code in conjunction with the code from your first post (specifically the portion before the start label), it tells me the username and password are incorrect instead of allowing me to define my own.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Require player-inputed text in a later text input?

#6 Post by Per K Grok »

Offworlder wrote: Sun Jul 21, 2019 4:35 am Unfortunately, this most recent example isn't quite working. If I use just the code from your second post, it gives me this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 47, in script
    show screen login1
  File "renpy/common/000statements.rpy", line 510, in execute_show_screen
    renpy.show_screen(name, *args, **kwargs)
Exception: Screen login1 is not known.
If I use the second code in conjunction with the code from your first post (specifically the portion before the start label), it tells me the username and password are incorrect instead of allowing me to define my own.
It is the original code with an addition an a small change. In my second post I only showed the part with the addition and the change.
This is the full code.

I works fine for me.

Code: Select all


init python:
    def logname_func(newstring):
        store.logname = newstring

    def logPW_func(newstring):
        store.logPW = newstring

default logname=""
default logPW=""


screen login1():
    frame:
        vbox:
            xsize 200
            ysize 100
            text "Enter name and password"
            text "Name:"
            frame:
                xsize 100
                input  changed logname_func length 15
            textbutton "Next" action [Show("login2"), Hide("login1")]

screen login2():
    frame:

        vbox:
            xsize 200
            ysize 100
            text "Password:"
            frame:
                xsize 100
                input changed logPW_func length 15
            textbutton "Login" action Jump("loginLabel")
            textbutton "Back" action [Show("login1"), Hide("login2")]


default IPname=""
default IPpass=""

###############################################################################

label start:

    scene red

    $ IPname=renpy.input("Enter your name:")
    $ IPpass=renpy.input("Chose password:")


    show screen login1

    $ renpy.pause(hard=True)

label loginLabel:

    if logname==IPname and logPW==IPpass:
        "Login succesful."
    else:
        "Name or password are incorrect."

    hide screen login2
    jump start


User avatar
Offworlder
Regular
Posts: 114
Joined: Mon Aug 20, 2018 6:33 pm
Contact:

Re: Require player-inputed text in a later text input?

#7 Post by Offworlder »

Per K Grok wrote: Sun Jul 21, 2019 4:56 am
It is the original code with an addition an a small change. In my second post I only showed the part with the addition and the change.
This is the full code.

I works fine for me.
Oh! I'm not sure what I did wrong the first time, but that definitely works. It'll take some finagling to get it set up the specific way I have in mind, but that's two conundrums solved. Thank you so much!

Even if it's not super straightforward, I'm positive there must be a way to have two selectable input boxes on the same screen.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Require player-inputed text in a later text input?

#8 Post by Per K Grok »

Offworlder wrote: Sun Jul 21, 2019 5:07 am
Even if it's not super straightforward, I'm positive there must be a way to have two selectable input boxes on the same screen.
I got an idea.

What if you have two inputs on a screen, but only show them one at a time and replace the one not showing with a string? I would expect the one showed to have focus.
You could use mouseareas to switch between which input would be shown.

So I tested the idea and it worked. It's a bit of a roundabout way of doing it, but ....

This is my code.

Code: Select all

init python:
    def logname_func(newstring):
        store.logname = newstring

    def logPW_func(newstring):
        store.logPW = newstring

default logname=""
default logPW=""

default IPname=""
default IPpass=""

default input1Show=1
default input2Show=0

screen login1():
    mousearea:
        area (0, 50, 100, 10)
        hovered SetVariable("input1Show", 1), SetVariable("input2Show", 0)

    mousearea:
        area (0, 65, 100, 10)
        hovered SetVariable("input1Show", 0), SetVariable("input2Show", 1)

    frame:
        vbox:
            xsize 200
            ysize 100
            text "Enter name and password"
            text "Name:"
            frame:
                xsize 100
                ysize 20
                if input1Show== 1:
                    input default logname  changed logname_func length 15
                else:
                    text logname color "#999"
            text "Password:"
            frame:
                xsize 100
                ysize 20
                if input2Show== 1:
                    input default logPW changed logPW_func length 15
                else:
                    text logPW color "#999"
            textbutton "Login" action Jump("loginLabel")



###############################################################################

label start:

    scene red

    $ IPname=renpy.input("Enter your name:")
    $ IPpass=renpy.input("Chose password:")


    show screen login1

    $ renpy.pause(hard=True)

label loginLabel:

    if logname==IPname and logPW==IPpass:
        "Login succesful."
    else:
        "Name or password are incorrect."

    $ logname=""
    $ logPW=""

    hide screen login1
    jump start



Post Reply

Who is online

Users browsing this forum: Google [Bot]