Page 1 of 1

One Time use Cheat Inputs

Posted: Mon Mar 21, 2022 4:30 pm
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

Re: One Time use Cheat Inputs

Posted: Mon Mar 21, 2022 4:45 pm
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)

Re: One Time use Cheat Inputs

Posted: Mon Mar 21, 2022 6:35 pm
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

Re: One Time use Cheat Inputs

Posted: Mon Mar 21, 2022 7:11 pm
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.

Re: One Time use Cheat Inputs

Posted: Mon Mar 21, 2022 7:32 pm
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