Help With A Password Input System

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
Wataru2
Newbie
Posts: 12
Joined: Sat Sep 29, 2018 11:04 am
Contact:

Help With A Password Input System

#1 Post by Wataru2 » Mon Oct 01, 2018 11:04 pm

I'm trying to make an input system in the middle of the screen that allows access to another screen in game. Basically I can do the standard

Code: Select all

If passwordinput = password then process next line, else jump back to label enterpassword
However, I want to achieve a more immersive way by allowing the input in the middle of the screen.

The problem with my code below is I can't progress even if I enter the string value of "Hi".

Code: Select all

screen passwordenter():
    modal True
    vbox:
        xalign 0.5 ypos 0.4
        text "what's the password?" 
        input
        if InputValue == "Hi":
           button:
                keysym "K_RETURN"
                action Jump("inGame1")
        if InputValue != "Hi":
            button:
                keysym "K_RETURN"
                action Jump("enterpassword")
label enterpassword:
    call screen passwordenter               

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

Re: Help With A Password Input System

#2 Post by Imperf3kt » Mon Oct 01, 2018 11:13 pm

Use renpy.input

I don't have an example in hand, but a working example can be found in my rock paper scissors cookbook guide. I will be updating it soon(ish) to use the _return value.

Download the .rpy "with cheats"
viewtopic.php?f=51&t=50068
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

Wataru2
Newbie
Posts: 12
Joined: Sat Sep 29, 2018 11:04 am
Contact:

Re: Help With A Password Input System

#3 Post by Wataru2 » Mon Oct 01, 2018 11:45 pm

Imperf3kt wrote:
Mon Oct 01, 2018 11:13 pm
Use renpy.input

I don't have an example in hand, but a working example can be found in my rock paper scissors cookbook guide. I will be updating it soon(ish) to use the _return value.

Download the .rpy "with cheats"
viewtopic.php?f=51&t=50068
Ah that solved the progression thanks! I'm wondering if there is a way to allow a text to show up if the password mismatches...
Right now i'm using screens and label to achieve it.

Code: Select all

default password = ""
screen passwordenter():
    modal True
    vbox:
        xalign 0.5 ypos 0.4
        text "what's the password?" 
        input:
            value VariableInputValue('password', returnable=False)
    if password == "Hi":
        button:
            keysym "K_RETURN"
            action Jump("inGame1")
    if password != "Hi":
        button:
            keysym "K_RETURN"
            action Jump("wrongpassword")
            
label wrongpassword:
    "I don't think that's the right password...."
    jump enterpassword            

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

Re: Help With A Password Input System

#4 Post by Imperf3kt » Mon Oct 01, 2018 11:54 pm

I have a different version which does exactly that. It is on my laptop at home though. I'll post it later.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

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

Re: Help With A Password Input System

#5 Post by Imperf3kt » Tue Oct 02, 2018 5:27 am

Maybe this can be modified to be of use?

Code: Select all

label delete_achievements:
    $ clearachieve = renpy.input('Input Password', length=9) or None
    if clearachieve == 'imperf3kt':
        $ achievement.clear_all()
        e "All your achievement are belong to me!"
    else:
        e "Access denied!"
    return
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

Wataru2
Newbie
Posts: 12
Joined: Sat Sep 29, 2018 11:04 am
Contact:

Re: Help With A Password Input System

#6 Post by Wataru2 » Tue Oct 02, 2018 4:54 pm

Imperf3kt wrote:
Tue Oct 02, 2018 5:27 am
Maybe this can be modified to be of use?

Code: Select all

label delete_achievements:
    $ clearachieve = renpy.input('Input Password', length=9) or None
    if clearachieve == 'imperf3kt':
        $ achievement.clear_all()
        e "All your achievement are belong to me!"
    else:
        e "Access denied!"
    return
You idea would work using labels! I managed to figured it out using Screen Language. This way if I wanted to customize certain things I can. Might be a bit longer but it's easier for the long run when I just call my screen passwordenter. Thanks for the idea!

Code: Select all

default password = ""
screen WrongPass():
    text "Access Denied." xalign 0.5 ypos 0.3 size 20
screen passwordenter():
    modal True

    vbox:
        xalign 0.5 ypos 0.4
        text "what's the password?" 
        input:
            value VariableInputValue('password', returnable=False)
    if password == "Hi":
        button:
            keysym "K_RETURN"
            action Jump("inGame1")
    else:
        button:
            keysym "K_RETURN"
            action [Show('WrongPass'), Jump("enterpassword")]
        key "K_BACKSPACE" action [SetVariable("password", ""), Hide("WrongPass")]
    vbox:
        xalign 0.5 ypos 0.6
        textbutton "Quit" action Return()
You could also simply use action [Notify("Access Denied!"), Jump("enterpassword")]. But with that, you'd need a few more lines of code to customize the text.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], DarkMinistry