Use a menu choice as a condition... is it possible

30avenger30

Member
Game Developer
May 27, 2018
127
523
Hey,
I'm using renpy.
I forgot to make a condition in my last update, so I was wondering if it's possible to use a certain choice from a menu as a condition for something else to happen later in the game?
for example... if I had a menu:
menu:
"day 9":
call day_9
"day 10":
call day_10

so, my question is if I can use a choice that the player made as a condition for something else to happen?
For example:
If day 9
call day_15

Thanks for the help
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
so, my question is if I can use a choice that the player made as a condition for something else to happen?
Variables and their meaning is totally up to you. As long as the condition make sense, it can be used for whatever you want.

Lets say that you've this code:
Code:
label whatever:
    menu:
        "Go to the park":
            jump inThePark
        "Stay at home":
            [...]

label inThePark:
    [...]
    menu:
       "Kiss her":
           $ kissed = True
           [...]
       "Don't kiss her":
           [...]
You can latter use kissed to know that the player goes to the park. It would left apart the players that goes to the park and didn't kissed the girl, but at least catch up the others.

This being said, take a look at my Variables compatibility how-to (link in my signature), it present few methods to solve this kind of issues.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
I can see two possible solutions (though being RenPy, there will be more).

First the easier of the two:

Python:
default day9_happened_already = False

label start:

    menu:
        "Day 9":
            jump day9

        "Day 10":
            jump day10


label day9:

    if day9_happened_already == True:
        jump day15

    $ day9_happened_already = True

    # continue with day 9

    jump somewhere


label day10:

    # do day 10 stuff
    jump somewhere


label day15:

    # do day 15 stuff
    jump somewhere

In this case, I'm setting up a variable I'm calling day9_happened_already and using it to decide if day9 or day15 should happen when "Day 9" is picked. The game will always go to the day9 label. But when it gets there, it might change direction.

The other solution is to use .

Python:
default day9_happened_already = False

label start:

    menu:
        "Day 9" if day9_happened_already == False:
            jump day9

        "Day 10":
            jump day10

        "Day 15" if day9_happened_already == True:
            jump day15

label day9:

    $ day9_happened_already = True

    # continue with day 9
    jump somewhere


label day10:

    # do day 10 stuff
    jump somewhere


label day15:

    # do day 15 stuff
    jump somewhere

In this case, the check is done as part of the menu: choice. Basically, you add an if to the menu choice. If the check is True, that menu choice is shown. If the check is False, that menu choice is hidden.

By having two if checks based on the same variable checking for True/False, only one of the two menu choices will be displayed - depending on what has already happened (i.e. the value of the variable).
 

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,750
16,546
Hey,
I'm using renpy.
I forgot to make a condition in my last update, so I was wondering if it's possible to use a certain choice from a menu as a condition for something else to happen later in the game?
for example... if I had a menu:
menu:
"day 9":
call day_9
"day 10":
call day_10

so, my question is if I can use a choice that the player made as a condition for something else to happen?
For example:
If day 9
call day_15

Thanks for the help
Basically, no, you can't use a choice from a menu as a condition unless you had variables set/changed by those choices in the menu. You'd either need to add the variables to menu choices and make players replay the game/certain parts or use other methods that are described in anne O'nymous' that they mentioned.
 

30avenger30

Member
Game Developer
May 27, 2018
127
523
Basically, no, you can't use a choice from a menu as a condition unless you had variables set/changed by those choices in the menu. You'd either need to add the variables to menu choices and make players replay the game/certain parts or use other methods that are described in anne O'nymous' that they mentioned.
Yeah, I figured that.
I'll just have to find a creative way around it.
Basically, I had 3 choices in mind but I forgot to add a variable for the third one.
I guess I can just leave it at two choices.
Thanks for everyone who tried to help.
 
  • Like
Reactions: LightmanP

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
I must admit, I misread the original question - so my answer... while accurate wasn't really answering your question.

But you talk about 3 choices... and having no variable for the 3rd.
Could a value be inferred from the lack of value in the other 2?

By which I mean something like:

Python:
default opt1 = False
default opt2 = False
default opt3 = False

label start:

    menu:
        "Option 1"
            $ opt1 = True

        "Option 2"
            $ opt2 = True

        "Option 3"
            "Ooops, I forgot."

    "*** THE END ***"
    return

Because I'm wondering if you could "assume" opt3 should be True if both opt1 and opt2 were both still False?

Because if that's the case, I can see a possible solution.

You don't have permission to view the spoiler content. Log in or register now.
 
  • Like
Reactions: LightmanP

30avenger30

Member
Game Developer
May 27, 2018
127
523
I must admit, I misread the original question - so my answer... while accurate wasn't really answering your question.

But you talk about 3 choices... and having no variable for the 3rd.
Could a value be inferred from the lack of value in the other 2?

By which I mean something like:

Python:
default opt1 = False
default opt2 = False
default opt3 = False

label start:

    menu:
        "Option 1"
            $ opt1 = True

        "Option 2"
            $ opt2 = True

        "Option 3"
            "Ooops, I forgot."

    "*** THE END ***"
    return

Because I'm wondering if you could "assume" opt3 should be True if both opt1 and opt2 were both still False?

Because if that's the case, I can see a possible solution.

You don't have permission to view the spoiler content. Log in or register now.
The first option is not relevant. I wish it was that easy.

I understand what your saying about the after_load option, and yes, it's a problem.
is there a way to make this work both when the player loads a save file and also when he starts a new game:
label after_load:
if renpy.seen_label("put_your_label_here"):
$ your_variable = True

if it's possible, then that is the solution for me.
 

LightmanP

Well-Known Member
Modder
Game Developer
Oct 5, 2020
1,750
16,546
The first option is not relevant. I wish it was that easy.

I understand what your saying about the after_load option, and yes, it's a problem.
is there a way to make this work both when the player loads a save file and also when he starts a new game:
label after_load:
if renpy.seen_label("put_your_label_here"):
$ your_variable = True

if it's possible, then that is the solution for me.
renpy.seen_label wouldn't work as good because it is not dependent on a particular save/playthrough but will return True if the label was seen at any point in time on the pc.

If you're going with after_load option, I'd do something like this:

Python:
default your_variable = None

label after_load:

    if your_variable is None:
        $ your_variable = True
       
    return
But here you make an assumption that people who are loading a save and haven't started a new game have passed that choice and a choice is kinda forced on them if there was one between day 9 or 10.
Perhaps it would just be better to ask players if they chose day 9 at the start of your new update.

For a new game just add the necessary variable change in the required menu.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
Basically, I had 3 choices in mind but I forgot to add a variable for the third one.
Wait, if you've two variables, then you can guess the third one.

Lets say that you've this:
Code:
default choiceOne = False
default choiceTwo = False

label whatever:
    menu:
        "Choice 1":
            $ choiceOne = True
            [...]
        "Choice 2":
            $ choiceTwo = True
            [...]
        "Choice 3":
            [...]
Then, there's three state after this menu:
  • choiceOne is True and choiceTwo is False ;
    The player picked the choice 1
  • choiceOne is False and choiceTwo is True ;
    The player picked the choice 2
  • choiceOne is False and choiceTwo is False ;
    The player picked the choice 3

Therefore, as long as you gave a default value to the two variables before the menu, you can catch up the issue.
 

30avenger30

Member
Game Developer
May 27, 2018
127
523
renpy.seen_label wouldn't work as good because it is not dependent on a particular save/playthrough but will return True if the label was seen at any point in time on the pc.

If you're going with after_load option, I'd do something like this:

Python:
default your_variable = None

label after_load:

    if your_variable is None:
        $ your_variable = True
      
    return
But here you make an assumption that people who are loading a save and haven't started a new game have passed that choice and a choice is kinda forced on them if there was one between day 9 or 10.
Perhaps it would just be better to ask players if they chose day 9 at the start of your new update.

For a new game just add the necessary variable change in the required menu.
Yeah, I see what you mean.
I didn't want to do that, but I guess there isn't any other choice.
Thanks again for your help. much appriciated.
 
  • Like
Reactions: LightmanP

30avenger30

Member
Game Developer
May 27, 2018
127
523
Wait, if you've two variables, then you can guess the third one.

Lets say that you've this:
Code:
default choiceOne = False
default choiceTwo = False

label whatever:
    menu:
        "Choice 1":
            $ choiceOne = True
            [...]
        "Choice 2":
            $ choiceTwo = True
            [...]
        "Choice 3":
            [...]
Then, there's three state after this menu:
  • choiceOne is True and choiceTwo is False ;
    The player picked the choice 1
  • choiceOne is False and choiceTwo is True ;
    The player picked the choice 2
  • choiceOne is False and choiceTwo is False ;
    The player picked the choice 3

Therefore, as long as you gave a default value to the two variables before the menu, you can catch up the issue.
Again, I wish it was that easy, but the third choice needs to have another variable that is unrelated to the other two.
 

30avenger30

Member
Game Developer
May 27, 2018
127
523
I actually managed to find a solution and it's a really easy one.
Basically the third choice is a condition of option one and another variable that I forgot to put on a "certain label" and it only happens on that "certain label".
so I did:
if option_1 >=2 and renpy.seen_label("certain label"):
call option_3

It works.
Thanks again to everyone.
I couldn't do it without your help.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
if renpy.seen_label("put_your_label_here"):

if it's possible, then that is the solution for me.

"probably" not.

As the others have already said, the problem with renpy.seen_label() is that is pretty much "has this label EVER been seen?"
If the player has only played the game once and never used rollback - then it's "probably" fine.
But as soon as that label is seen - it is seen forever. It doesn't matter that the label hasn't been seen during the current playthrough. Which makes it good for things like achievements - but bad for things like this.

I must admit, when using label after_load: - I tend towards using default {variable} = None instead of a "real" value and then doing the equivalent of $ opt3 = False just before the value is used properly. I just didn't want to muddy the waters, if the simpler solution was okay for you.

Last time I went into something like this... I went with a pragmatic solution. I set the default value to None and set it to False just before the menu: choices. I checked for None in the after_load - and used renpy.seen_label() to set the value based on my best guess what "most players" would have picked. I then followed that up with a few if checks based on other variables to override the value if my best guess couldn't possibly be true - because the combination of all those variables would normally be impossible.

It's not 100% perfect. But it's usually 90% there for "most" players.
Sometimes you just have to accept that "good enough" is good enough.
 
  • Like
Reactions: LightmanP

30avenger30

Member
Game Developer
May 27, 2018
127
523
has this label EVER been seen?
renpy.seen_label wouldn't work as good because it is not dependent on a particular save/playthrough but will return True if the label was seen at any point in time on the pc.
Damn... you guys are right. I can't take that chance that someone got to that label by just playing around :(
I already know the answer to the question, but I'll give it a shot anyway.
Is there a way to make this relevant only to the playthrough the player is on?

Thanks again
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Is there a way to make this relevant only to the playthrough the player is on?

Nope.

When I asked the same question on the official RenPy forums, I think the closest solution I was offered was to do some botched version of "delete the game's persistent data each time the player uses {Start} instead of {Load}". But that just causes a mass of other problems and doesn't fix the issue of players using rollback to tryout different choices before settling on one.

By all means, use renpy.seen_label() and if {variable} == None... just know that sometimes, it will be wrong. As much as, we as programmers, will be concerned about this exceptions... the majority of players will just play the game and play it once.
 
Last edited:
  • Like
Reactions: 30avenger30