One Time use Cheat Inputs

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
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

One Time use Cheat Inputs

#1 Post by lsf22 »

Renpy Version used is 7.4.11
Trying to implement a cheat function for the game, as one that only allows a cheat password to be used only once

Example of something I have worked on but I don't have it working correctly. That code is just a simple test of it

Code: Select all

define e = Character("Eileen")
default Cheat_Money = False
default Money = 0
default Wellness = 0
default Cheat_Wellness = False

# The game starts here.
label start:
    e "Today we are testing out cheats"
    e "So please enter a cheat"

    menu:
        "Cheat Input":
            $ renpy.input("Enter a cheat")
            if renpy.input == "Add Money":
                $ Money +=100
                $ Cheat_Money = True
                "You have entered the correct cheat for Money"
            if Cheat_Money == True:
                "Cheat was already entered before"
                jump start

            if renpy.input == "Wellness Up":
                $ Wellness +=10
                $ Cheat_Wellness = True
                "You have entered the correct cheat for Wellness"
            if Cheat_Wellness == True:
                "Cheat was already entered before"
                jump start
            else:
                "You did not enter a correct cheat phrase"
                jump start

    e "So did you enter any cheats correctly?"
    return

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: One Time use Cheat Inputs

#2 Post by emz911 »

Follow the code from top to bottom and you'll understand why it doesn't work. You are checking the input result first, and then checking Check_Money, you want it the other way around. Also, you may want to use "and", "or", "elif" in these conditions:

Code: Select all

        if renpy.input == "Add Money" or renpy.input == "Wellness Up":
            if renpy.input == "Add Money" and Cheat_Money == False:
                $ Money +=100
                $ Cheat_Money = True
                "You have entered the correct cheat for Money"
            elif renpy.input == "Add Money" and Cheat_Money == True:
                "Cheat was already entered before"
                jump start
            elif renpy.input == "Wellness Up" and Cheat_Wellness == False:
                $ Wellness +=10
                $ Cheat_Wellness = True
                "You have entered the correct cheat for Wellness"
            elif renpy.input == "Wellness Up" and Cheat_Wellness == True:
                "Cheat was already entered before"
                jump start
        else:
            "You did not enter a correct cheat phrase"
             jump start
There are multiple ways of writing this, for example using "not Cheat_Wellness" instead of "Cheat_Wellness == False", and combining multiple conditions into one line using () brackets and "or" conditions to avoid copy and pasting lines with the same results... First get used to this code, then we can simplify it a bit more. (The indentation is a little messed up here, but notice there are two levels of indentation here)

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: One Time use Cheat Inputs

#3 Post by lsf22 »

For some reason it's going to the else statement when the password "Add Money" or "Wellness Up" is entered correctly

This is what the code looks like now:

Code: Select all

define e = Character("Eileen")
default Cheat_Money = False
default Money = 0
default Wellness = 0
default Cheat_Wellness = False

# The game starts here.
label start:
    e "Today we are testing out cheats"
    e "So please enter a cheat"

    menu:
        "Cheat Input":
            $ renpy.input("Enter a cheat")
            if renpy.input == "Add Money" or renpy.input == "Wellness Up":
                if renpy.input == "Add Money" and Cheat_Money == False:
                    $ Money +=100
                    $ Cheat_Money = True
                    "You have entered the correct cheat for Money"
                elif renpy.input == "Add Money" and Cheat_Money == True:
                    "Cheat was already entered before"
                    jump start
                elif renpy.input == "Wellness Up" and Cheat_Wellness == False:
                    $ Wellness +=10
                    $ Cheat_Wellness = True
                    "You have entered the correct cheat for Wellness"
                elif renpy.input == "Wellness Up" and Cheat_Wellness == True:
                    "Cheat was already entered before"
                    jump start
            else:
                "You did not enter a correct cheat phrase"
                jump start

    e "So did you enter any cheats correctly?"
    return

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2405
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: One Time use Cheat Inputs

#4 Post by Ocelot »

renpy.input is a function. It cannot be equal to string.

You probably wanted to save result of function invocation into varaible and compare that.
< < insert Rick Cook quote here > >

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: One Time use Cheat Inputs

#5 Post by lsf22 »

Thank you both. I went back and revised it. So far it works now and I was able to check the results with the variable viewer

Here is the code:

Code: Select all

define e = Character("Eileen")
default Cheat_Money = False
default Money = 0
default Wellness = 0
default Cheat_Wellness = False
default Cheat_Password_input = ""

# The game starts here.
label start:
    e "Today we are testing out cheats"
    e "So please enter a cheat"

    menu:
        "Cheat Input":
            $ Cheat_Password_input = renpy.input("Enter a cheat")
            if Cheat_Password_input == "Add Money" or Cheat_Password == "Wellness Up":
                if Cheat_Password_input == "Add Money" and Cheat_Money == False:
                    $ Money +=100
                    $ Cheat_Money = True
                    "You have entered the correct cheat for Money"
                elif Cheat_Password_input == "Add Money" and Cheat_Money == True:
                    "Cheat was already entered before"
                    jump start
                elif Cheat_Password_input == "Wellness Up" and Cheat_Wellness == False:
                    $ Wellness +=10
                    $ Cheat_Wellness = True
                    "You have entered the correct cheat for Wellness"
                elif Cheat_Password_input == "Wellness Up" and Cheat_Wellness == True:
                    "Cheat was already entered before"
                    jump start
            else:
                "You did not enter a correct cheat phrase"
                jump start

    e "So did you enter any cheats correctly?"
    menu:
        "Yes":
            pass
        "No":
            jump start
        "Let me test it out more":
            jump start
    return

Post Reply

Who is online

Users browsing this forum: No registered users