Problem with input text box on screen [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
LittleRainySeasons
Regular
Posts: 41
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Problem with input text box on screen [SOLVED]

#1 Post by LittleRainySeasons »

Okay so I'm making a custom screen text box for a portion of my game where the content is password protected. I decided to copy the code from here but the problem is I'm not sure how to hide the password from the text box and putting "else" automatically says wrong password by default.

Here's what I did:

Code: Select all

default password = "hellothere"
init python:
    def password_func(newstring):
        store.password = newstring
        
    style.input.size = 13
    style.input.color = "#000"
    
screen text_input_screen():
    default screenvar = False
    $ returnpage = True
    imagebutton idle "images/computer/passbox.png" xpos 260 ypos 369 focus_mask True action SetScreenVariable("screenvar",True)
    imagebutton idle "images/computer/returnbutton.png" xpos 13 ypos 539 focus_mask True action Jump("loginanim")
    imagebutton:
        idle "images/computer/confirm_idle.png"
        selected_idle "images/computer/confirm_selected.png"
        xpos 551 ypos 368
        focus_mask True
        action [Hide("text_input_screen"),Jump("adminwelcome")]
        
    if screenvar == True:
        input default password pos(272,379) changed password_func
        
    else:
        text "WRONG PASSWORD!" size 10 font "gui/PressStart2P-Regular.ttf" xpos 326 ypos 418 color "#a80020"
I also want to put a max length for the input box but I don't know where to put it and I always get an error. (I'm not really an experienced coder)
Last edited by LittleRainySeasons on Tue Nov 21, 2023 11:08 pm, edited 2 times in total.

User avatar
LittleRainySeasons
Regular
Posts: 41
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Re: Problem with input text box on screen

#2 Post by LittleRainySeasons »

I have found a way to fix the problem by removing the password.func
But then there's another problem, whenever I click the button it still shows wrong password even I input the right text and it won't proceed in the label:

Code: Select all

default password = ""

screen text_input_screen():
    default screenvar = False
    $ returnpage = True
    imagebutton idle "images/computer/passbox.png" xpos 260 ypos 369 focus_mask True action SetScreenVariable("screenvar",True)
    imagebutton idle "images/computer/returnbutton.png" xpos 13 ypos 539 focus_mask True action Jump("loginanim")
    imagebutton:
        idle "images/computer/confirm_idle.png"
        selected_idle "images/computer/confirm_selected.png"
        xpos 551 ypos 368
        focus_mask True
        if password == "hellothere":
            action Jump("adminwelcome")
        else:
            action Show("errortext")
        
    if screenvar == True:
        input default password pos(272,379)
        
screen errortext:
    text "WRONG PASSWORD!" size 10 font "gui/PressStart2P-Regular.ttf" xpos 326 ypos 418 color "#a80020"

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

Re: Problem with input text box on screen

#3 Post by m_from_space »

LittleRainySeasons wrote: Mon Nov 20, 2023 7:47 pm But then there's another problem, whenever I click the button it still shows wrong password even I input the right text and it won't proceed in the label:
You forgot to actually put in a value object for the input field. Without it, it's not changing any variable in the background. At the moment you just have an input field with some default text inside it.

Code: Select all

input value VariableInputValue("password") default password pos (272,379)
If you want to mask your password (e.g. with a star) and also define a maximum length (e.g. 32 in this case) do:

Code: Select all

input value VariableInputValue("password") default password mask "*" length 32 pos (272,379)

User avatar
LittleRainySeasons
Regular
Posts: 41
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Re: Problem with input text box on screen

#4 Post by LittleRainySeasons »

m_from_space wrote: Tue Nov 21, 2023 2:59 am
LittleRainySeasons wrote: Mon Nov 20, 2023 7:47 pm But then there's another problem, whenever I click the button it still shows wrong password even I input the right text and it won't proceed in the label:
You forgot to actually put in a value object for the input field. Without it, it's not changing any variable in the background. At the moment you just have an input field with some default text inside it.

Code: Select all

input value VariableInputValue("password") default password pos (272,379)
If you want to mask your password (e.g. with a star) and also define a maximum length (e.g. 32 in this case) do:

Code: Select all

input value VariableInputValue("password") default password mask "*" length 32 pos (272,379)
I actually finally found a solution by doing this. I tried the password mask thing and it says "invalid syntax"

Code: Select all

define password_input = VariableInputValue(variable = "password", returnable = True)

screen text_input_screen():
    default screenvar = False
    modal True
    imagebutton idle "images/computer/passbox.png" xpos 260 ypos 369 focus_mask True action SetScreenVariable("screenvar",True)
    
    if screenvar == True:
        add Input(default=password, length=14, value=password_input) pos(272,379)
Also is there a way to disable the enter key when inputting the wrong password? Because whenever I do press enter instead of the button, it triggers the welcome page instead of "WRONG PASSWORD"

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

Re: Problem with input text box on screen

#5 Post by m_from_space »

LittleRainySeasons wrote: Tue Nov 21, 2023 3:58 am I tried the password mask thing and it says "invalid syntax"
Which Renpy version are you using? Because it's pretty valid and works like a charm on my end.

I'm not sure why you are using a complicated way like creating an Input object and then adding it as a Displayable, while Renpy supports using the syntax I provided. Here you can read about the "input" keyword for screens: https://www.renpy.org/doc/html/screens.html#input
Also is there a way to disable the enter key when inputting the wrong password? Because whenever I do press enter instead of the button, it triggers the welcome page instead of "WRONG PASSWORD"
Yes, just overwrite the key.

Code: Select all

screen text_input_screen():
    key "K_RETURN" action NullAction()
    # ...

User avatar
LittleRainySeasons
Regular
Posts: 41
Joined: Fri Mar 24, 2017 9:37 am
Projects: Patsy n' Crinkles, Galaxy Party, Time|Reversed
Deviantart: LittleRainySeasons
Soundcloud: RoboticDreamz
itch: LittleRainySeasons
Contact:

Re: Problem with input text box on screen

#6 Post by LittleRainySeasons »

m_from_space wrote: Tue Nov 21, 2023 8:16 am
LittleRainySeasons wrote: Tue Nov 21, 2023 3:58 am I tried the password mask thing and it says "invalid syntax"
Which Renpy version are you using? Because it's pretty valid and works like a charm on my end.

I'm not sure why you are using a complicated way like creating an Input object and then adding it as a Displayable, while Renpy supports using the syntax I provided. Here you can read about the "input" keyword for screens: https://www.renpy.org/doc/html/screens.html#input
Also is there a way to disable the enter key when inputting the wrong password? Because whenever I do press enter instead of the button, it triggers the welcome page instead of "WRONG PASSWORD"
Yes, just overwrite the key.

Code: Select all

screen text_input_screen():
    key "K_RETURN" action NullAction()
    # ...
Finally figured it out. Thanks for the help!

Post Reply

Who is online

Users browsing this forum: No registered users