How to implement an unlock code input field

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
thirstyoctopus
Regular
Posts: 54
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

How to implement an unlock code input field

#1 Post by thirstyoctopus » Thu Mar 21, 2019 1:59 pm

Hey guys

I'm currently in the middle of producing a game that was funded on Kickstarter, and I want to be able to add a menu option called Bonus Codes or Unlock Codes or something similiar which would open a new screen or page that simply has an input field and a button - when a user enters a specific code I want it to unlock an option in preferences (I'll do the conditional using a global variable) but how do I actually implement this kind of functionality? Is it possible?

The reason I need to do this is due to the tier rewards in Kickstarter, I need to issue bonus codes to unlock a certain modes for different backers.

Any help is much apprecated - or any suggestions on how it could be acheieved a different way? Like maybe sending my backers a specific DLC file that installs it instead??

User avatar
Kia
Miko-Class Veteran
Posts: 867
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: How to implement an unlock code input field

#2 Post by Kia » Fri Mar 22, 2019 5:02 am

there are many different approaches to do this, but to put it simple you have conditions to check and actions to perform if they are true.
the easiest route is storing the user's input and comparing it to a list of strings in an "if, elif, else" sequence.

User avatar
thirstyoctopus
Regular
Posts: 54
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to implement an unlock code input field

#3 Post by thirstyoctopus » Fri Mar 22, 2019 6:23 am

Kia wrote:
Fri Mar 22, 2019 5:02 am
there are many different approaches to do this, but to put it simple you have conditions to check and actions to perform if they are true.
the easiest route is storing the user's input and comparing it to a list of strings in an "if, elif, else" sequence.
Yes, I understand that part, it's just I can't find documentation on how to actually place a submittable form field in a menu screen. I know you can have a name input in the dialogue text box within the game - is it pretty much the same deal?

User avatar
Kia
Miko-Class Veteran
Posts: 867
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: How to implement an unlock code input field

#4 Post by Kia » Fri Mar 22, 2019 6:59 am


User avatar
thirstyoctopus
Regular
Posts: 54
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to implement an unlock code input field

#5 Post by thirstyoctopus » Fri Mar 22, 2019 7:41 am

Kia wrote:
Fri Mar 22, 2019 6:59 am
ah you need screens then: https://www.renpy.org/doc/html/screens.html#input
Thank you!

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

Re: How to implement an unlock code input field

#6 Post by Imperf3kt » Fri Mar 22, 2019 7:43 pm

Input can also be used within dialogue.
I haven't got an example on hand, but I'll post one later.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

User avatar
thirstyoctopus
Regular
Posts: 54
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to implement an unlock code input field

#7 Post by thirstyoctopus » Fri Mar 22, 2019 8:27 pm

Kia wrote:
Fri Mar 22, 2019 6:59 am
ah you need screens then: https://www.renpy.org/doc/html/screens.html#input
I'm afraid I'm still stumped. I've added some code to display an input box but I see no feasible way of recording what the user has entered. This is what I have (based on the documentation):

Code: Select all

screen bonus_content():

    tag menu

    use game_menu(_("Bonus Content"), scroll="viewport"):

        style_prefix "bonus_content"

        vbox:

            label _("Bonus Content\n")
            text _("Have an unlock code? Type it below and hit Submit.")

            input default ""
            textbutton "Submit" action Return(True)
and although that works, since it's not a renpy input (like what you would get when a player is prompted for name within a dialogue for example) I don't know how or where to save what is entered.

Further help on this would be much appreciated.

User avatar
Kia
Miko-Class Veteran
Posts: 867
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: How to implement an unlock code input field

#8 Post by Kia » Sat Mar 23, 2019 1:34 pm

sorry for the delay, had some guest to entertain.
here's the general idea and as simple as I can make it. if you have a big list of conditions, you might want to put them in a list and check them in a loop.

Code: Select all

screen input_scr:
    default inp = ""
    vbox:
        frame:
            xsize 300
            input:
                value ScreenVariableInputValue("inp")
        button:
            text "Enter"
            action If(inp == "good", Jump("somewhere"))
        if inp == "ano":
            text "another"
        elif inp == "more":
            text "even more"

User avatar
Andredron
Veteran
Posts: 338
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How to implement an unlock code input field

#9 Post by Andredron » Sun Mar 24, 2019 6:05 am

I know, I'm writing terribly in English.

I'm writing a Renpy textbook (in Russian). https://yadi.sk/d/ZX_DonP63USRru Update 22.06.18

Translating to Russian language

Honest Critique

User avatar
thirstyoctopus
Regular
Posts: 54
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to implement an unlock code input field

#10 Post by thirstyoctopus » Sun Mar 24, 2019 1:47 pm

Kia wrote:
Sat Mar 23, 2019 1:34 pm
sorry for the delay, had some guest to entertain.
here's the general idea and as simple as I can make it. if you have a big list of conditions, you might want to put them in a list and check them in a loop.

Code: Select all

screen input_scr:
    default inp = ""
    vbox:
        frame:
            xsize 300
            input:
                value ScreenVariableInputValue("inp")
        button:
            text "Enter"
            action If(inp == "good", Jump("somewhere"))
        if inp == "ano":
            text "another"
        elif inp == "more":
            text "even more"
Thanks for your help - I'll give this a try when I next get to working on my project.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]