Ren'Py Menu Choice problem

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
This is what i like to do.

Very simple but i failed to make it actually work.

5 choices but i want to have each choice only once selectable.

So i tried something like this

default wasselected = False

choice1:
"Take fruit" if wasselected == False:
blabla...

I think i am missing something.
So embarrassing.

I think i just want to have the choice visible but inactive.
Or another way could be, to have it visible but not counting anymore for values.

Thank you

p.s. do i need to make for each choice defaults? That would be long list. If this is what i need to do, i have to make them.

Code:
init:
default choice01 = False
default choice02 = False
default choice03 = False
default choice04 = False
default choice05 = False
 
 
 label start:
 menu scene01:
        "Sure, why not? He seems trustworthy." if choice01 == False:
            "Yes. I like him. He understands me."
            jump agree
            $ obedient +=1
            $ shy -=1
            $ trust +=1
            "No way. I think i changes my mind."
            jump exitscene
            $ confidence -= 10
        "Am i really going to this?" if choice02 == False:
            "Let me thin about it one more time."
            $ obedient -=1
            $ shy +=1
            jump scene01                   
        "Please, tell me a joke." if choice03 == False:
            "Do you know any joke? Make me laugh again."
            jump joke
            $ obedient -=1
            $ shy +=1
        "What are these pictures you have?" if choice04 == False:
            "These pictures. Are you a pervert or what?"
            jump pictures
            $ obedient -=1
            $ shy +=1
        "Is this alcohol you have on the desk?" if choice05 == False:
            "I could use a drink. This what i am doing anyway when i home."
            jump alcohol
            $ obedient -=1
            $ shy +=1
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,143
14,828
5 choices but i want to have each choice only once selectable.
Then what you are looking for is the menu property:

[Note: roughly based on your original code]
Python:
#  Generally a single set is enough for all the menus, at least
# unless you need to go back and forth from one to another.
default genericMenuSet = set()

label start:

    # Reset it right before the menu to have a clean set.
    $ genericMenuSet = set()

    menu scene01:
        # Declare the set.
        set genericMenuSet

        # No need to condition the choice, Ren'Py will do it automatically.
        "Sure, why not? He seems trustworthy.":
            [...]
            jump scene01
        "Am i really going to this?":
            [...]
            jump scene01
        "Please, tell me a joke.":
            [...]
            jump scene01
        "What are these pictures you have?":
            [...]
            jump scene01
        "Is this alcohol you have on the desk?":
            [...]
            jump scene01

As for what you were doing wrong, it's relatively simple, but easy to miss when you are novice:

You used flags variable, what it correct.
You conditioned the menu choice to the flag being lowered, what is also correct.

But you forgot to raise the flag when the choice is picked:
Python:
menu:
    "choice 1" if choice1 == False:
        $ choice1 = True
        [...]
    "choice 2" if not choice2:
        $ choice2 = True
        [...]
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
Then what you are looking for is the menu property:

[Note: roughly based on your original code]
Python:
#  Generally a single set is enough for all the menus, at least
# unless you need to go back and forth from one to another.
default genericMenuSet = set()

label start:

    # Reset it right before the menu to have a clean set.
    $ genericMenuSet = set()

    menu scene01:
        # Declare the set.
        set genericMenuSet

        # No need to condition the choice, Ren'Py will do it automatically.
        "Sure, why not? He seems trustworthy.":
            [...]
            jump scene01
        "Am i really going to this?":
            [...]
            jump scene01
        "Please, tell me a joke.":
            [...]
            jump scene01
        "What are these pictures you have?":
            [...]
            jump scene01
        "Is this alcohol you have on the desk?":
            [...]
            jump scene01

As for what you were doing wrong, it's relatively simple, but easy to miss when you are novice:

You used flags variable, what it correct.
You conditioned the menu choice to the flag being lowered, what is also correct.

But you forgot to raise the flag when the choice is picked:
Python:
menu:
    "choice 1" if choice1 == False:
        $ choice1 = True
        [...]
    "choice 2" if not choice2:
        $ choice2 = True
        [...]
lol

I am lame.

I tried this before and for some reason when i did the way i did it, it ended up always that it was true from the beginning without selecting the choice in the first place.
This is what i did.

Code:
init:

default choice01 = False
default choice02 = False
default choice03 = False
default choice04 = False
default choice05 = False
#################################################################################
define config.menu_include_disabled = True # this i included because it suppose to make the choice still visible.

start label:

   menu scene01:
        "Sure, why not? He seems trustworthy." if choice01 == True:
            "Yes. I like him. He understands me."
            $ obedient +=1
            $ shy -=1
            $ trust +=1
            $ choice01 = True
            jump agree           
            "No way. I think i changes my mind."
            jump exitscene
            $ confidence -= 10
        "Am i really going to this?" if choice02 == True:
            "Let me thin about it one more time."
            $ obedient -=1
            $ shy +=1
#            $ choice02 = True       
            jump scene01
When looking at the second choice. It should check if the condition is true, which should be false.
Later down the code, the condition should be set to True. But i probably did a mental mistake because no matter what, it always was greyed out before i could select the choice.


Btw. what is better. Have all choice visible at all times or make them invisible? I am kind of torn but i think having the visible is probably better.

Anyway, i will test your suggestion. Me doing coding. lol... Thank you so much.
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
Then what you are looking for is the menu property:

[Note: roughly based on your original code]
Python:
#  Generally a single set is enough for all the menus, at least
# unless you need to go back and forth from one to another.
default genericMenuSet = set()

label start:

    # Reset it right before the menu to have a clean set.
    $ genericMenuSet = set()

    menu scene01:
        # Declare the set.
        set genericMenuSet

        # No need to condition the choice, Ren'Py will do it automatically.
        "Sure, why not? He seems trustworthy.":
            [...]
            jump scene01
        "Am i really going to this?":
            [...]
            jump scene01
        "Please, tell me a joke.":
            [...]
            jump scene01
        "What are these pictures you have?":
            [...]
            jump scene01
        "Is this alcohol you have on the desk?":
            [...]
            jump scene01

As for what you were doing wrong, it's relatively simple, but easy to miss when you are novice:

You used flags variable, what it correct.
You conditioned the menu choice to the flag being lowered, what is also correct.

But you forgot to raise the flag when the choice is picked:
Python:
menu:
    "choice 1" if choice1 == False:
        $ choice1 = True
        [...]
    "choice 2" if not choice2:
        $ choice2 = True
        [...]
This works. I didn't expect anything less. :)

Though i removes the choice which goes back to my question what is better for a player. Perhaps someone likes to replay that choice but i would not want to have it as a cheat of sorts where you accumulate points through it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,143
14,828
I am lame.
No you aren't.

You are doing something that is purely logical, but if being purely logical was enough to write code, classes would be way shorted.
In top of this, you're learning on your own, knowing that coding isn't necessarily as easy as it looks. This put a bit more pressure on your shoulders. In the end, you were focused on "I need to find a way to condition the choices", and it's what you did. But like you were focused on this conditioning, you didn't see the small bit on the side ; the flag need to be raised.

Too often the way I answer make it looks like it's easy and obvious... But it's only because, counting the time I did it as amateur when I was still a teenager, I've probably a bit more than 35 years of practice ; passed a certain age, you don't like to have precise count ;)
You're seeing me at my best, not the lame me I was 35 years ago, nor the lame me I still can be, time to time, when I'm trying to find an answer to a more complex question. You see the dozen lines of code I'll write, not the dozen attempt to reach to this short code. You see the elegant solution, not the ugly ones I tried before finding it.


Never forget this, and it don't limit to code, when you read something online, you're seeing a result, not the possible hours or days of thinking that lead to this result. So never feel lame because you didn't thought "about this". It's not impossible that the person telling it to you never thought about it two minutes before he wrote it.
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
No you aren't.

You are doing something that is purely logical, but if being purely logical was enough to write code, classes would be way shorted.
In top of this, you're learning on your own, knowing that coding isn't necessarily as easy as it looks. This put a bit more pressure on your shoulders. In the end, you were focused on "I need to find a way to condition the choices", and it's what you did. But like you were focused on this conditioning, you didn't see the small bit on the side ; the flag need to be raised.

Too often the way I answer make it looks like it's easy and obvious... But it's only because, counting the time I did it as amateur when I was still a teenager, I've probably a bit more than 35 years of practice ; passed a certain age, you don't like to have precise count ;)
You're seeing me at my best, not the lame me I was 35 years ago, nor the lame me I still can be, time to time, when I'm trying to find an answer to a more complex question. You see the dozen lines of code I'll write, not the dozen attempt to reach to this short code. You see the elegant solution, not the ugly ones I tried before finding it.


Never forget this, and it don't limit to code, when you read something online, you're seeing a result, not the possible hours or days of thinking that lead to this result. So never feel lame because you didn't thought "about this". It's not impossible that the person telling it to you never thought about it two minutes before he wrote it.
Well, of course you are right.

Sometimes, when i think i should find the error myself, and i didn't, i question myself why i didn't see it.
But yes, experience makes the master.
I want to understand what i am coding. Because it would be useless to code and not understand and in this case, i tried something simple and really thought about if i do X then Y should happen. And it didn't.
So back to the drawing board.

Like the suggestion you pointed out, i want to understand it so i comprehend what it actually does.

I just seen that RenPy overhauled their docs. Looks really nice but i wished they had more examples.

What i will do is, to take my dummy guide that i bought a year ago and learn Python with examples. I just want or need to find something small that i can do with it.

It's quite a relieve knowing that you are here so i can get a solution i never would have thought off myself.

Thanks again, you are my savior. ;)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,143
14,828
Sometimes, when i think i should find the error myself, and i didn't, i question myself why i didn't see it.
You are not ready to hear how often long time professionals can pass way to much time trying to figure a stupidly simple error. And it's good, because I guess there's not many who are ready to admit it ;)

But it happen often enough for to be something and to have its own wikipedia page...
Of course, it generally regard errors more complex than the one you had here, because professionals generally works on more complex algorithms. But more complex do not mean less stupids. And the fact that explaining out loud the problem can be enough to find the error, tell how "stupid" it those errors can be.

"So, you see, I have this recursive function that browse [whatever] branch by branch, but for a strange reason it only return the content of the first level. It's something simple, I loop through the entry at this level, and for each entry call the function itself, for it to loop through [blablabla]. Obviously, I haven't forgot to return what the function found... But yeah, you're right little rubber duck, I totally forgot to catch the returned value... No, no need to say it, I know, I'm idiot..."
 
  • Like
Reactions: coffeeaddicted

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
You are not ready to hear how often long time professionals can pass way to much time trying to figure a stupidly simple error. And it's good, because I guess there's not many who are ready to admit it ;)

But it happen often enough for to be something and to have its own wikipedia page...
Of course, it generally regard errors more complex than the one you had here, because professionals generally works on more complex algorithms. But more complex do not mean less stupids. And the fact that explaining out loud the problem can be enough to find the error, tell how "stupid" it those errors can be.

"So, you see, I have this recursive function that browse [whatever] branch by branch, but for a strange reason it only return the content of the first level. It's something simple, I loop through the entry at this level, and for each entry call the function itself, for it to loop through [blablabla]. Obviously, I haven't forgot to return what the function found... But yeah, you're right little rubber duck, I totally forgot to catch the returned value... No, no need to say it, I know, I'm idiot..."
I think this is a great idea. Sounds stupid or irritating at first but i once had a teacher that said, the best way to learn is to
a) write it out
b) read it aloud
c) repeat. (i am not sure about the 3th)
So this rubber duck is actually a great idea and i won't feel embarrassed talking to it.

I try to imagine code very complex. In the book i mentioned there is a chapter for a database. So to make an error there is really simple i think.
I am not sure how coders (the professional type) go about it to locate an error. I go just line by line unless it tells me in line x is this expected.

But yes, i like the idea :)
 

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
Oh there is one thing i am hunting for.

I came up with the idea to have the MC look at you when there is a choice.
Sound great in theory but in practice that doesn't seem to work.

From what i understand, menu choice doesn't comply with the usual commands to display an image.
So a command like show won't do anything.
Is there a workaround to have images shown for different choices?
I know, it sounds weird.
All i remember is that menu is a graphical thing. Meaning it works with screens. I think.

If not workable i will just show an image before the menu.
Just an idea anyway.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,143
14,828
From what i understand, menu choice doesn't comply with the usual commands to display an image.
So a command like show won't do anything.
Is there a workaround to have images shown for different choices?
Perhaps, everything depend what you effectively want to do.


Python:
screen choice(items):
    style_prefix "choice"

    # Everything child will be placed staring the top left corner.
    fixed:
        #  Darken the current image.
        add Solid( "#000000DD" ) ) size ( config.screen_width, config.screen_height )
        #  Show the MC looking right at the player in top of everything.
        # You can do the same with a single /add/ if you directly use #000000DD
        # as color for the image background.
        add "images/mc_look_at_you.jpg"

    vbox:
        for i in items:
            textbutton i.caption action i.action
This would make the MC appear in top of the current image, looking right at the player.

Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                #  Same than above, it's possible to do it with only one image.
                hovered [ Function( renpy.show, Solid( "#000000DD" ) ), Function( renpy.show, "images/mc_look_at_you.jpg" ) ]
This would make the MC appear in top of the current image, looking right at the player, but only when a choice is hovered.


And I guess that something like this is perhaps possible:
/!\ It's totally experimental and untested /!\
Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                hovered Function( renpy.show, "mc looking at player" )
This should replace MC sprite by one where he look at the player, every time the player hover a menu choice. What imply that the MC have a sprite and that its name starts by "mc" ; it's based on the basic substitution that happen with show.
But as I said, it's untested. I have no idea if the sprite would return back to the original one once the choice isn't hovered anymore.
It also imply that the MC will appear out of nowhere if its sprite isn't actually shown on screen.
 
  • Like
Reactions: coffeeaddicted

coffeeaddicted

Well-Known Member
Apr 13, 2021
1,738
1,421
Perhaps, everything depend what you effectively want to do.


Python:
screen choice(items):
    style_prefix "choice"

    # Everything child will be placed staring the top left corner.
    fixed:
        #  Darken the current image.
        add Solid( "#000000DD" ) ) size ( config.screen_width, config.screen_height )
        #  Show the MC looking right at the player in top of everything.
        # You can do the same with a single /add/ if you directly use #000000DD
        # as color for the image background.
        add "images/mc_look_at_you.jpg"

    vbox:
        for i in items:
            textbutton i.caption action i.action
This would make the MC appear in top of the current image, looking right at the player.

Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                #  Same than above, it's possible to do it with only one image.
                hovered [ Function( renpy.show, Solid( "#000000DD" ) ), Function( renpy.show, "images/mc_look_at_you.jpg" ) ]
This would make the MC appear in top of the current image, looking right at the player, but only when a choice is hovered.


And I guess that something like this is perhaps possible:
/!\ It's totally experimental and untested /!\
Python:
screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption:
                action i.action
                hovered Function( renpy.show, "mc looking at player" )
This should replace MC sprite by one where he look at the player, every time the player hover a menu choice. What imply that the MC have a sprite and that its name starts by "mc" ; it's based on the basic substitution that happen with show.
But as I said, it's untested. I have no idea if the sprite would return back to the original one once the choice isn't hovered anymore.
It also imply that the MC will appear out of nowhere if its sprite isn't actually shown on screen.
From reading the description, option a seems what comes close.
The important thing is, you can't just add or show an image since this is a box.
But it's an option. Now i have to see if it works as intended. If it has the effect i was aiming for.
Man, i would never thought of this.
So glad you know it.

Upon reading and browsing RenPy doc i found there is even an option to make bubbles for dialogs. This is amazing. Not sure how that looks in practice but this is something rather unique.
Though i like to keep it simple. For now it's more of an exercise than anything.
I kind of like playing with RenPy and there are many, really many, things i don't really understand. So learning by doing and relaying on the wisdom of yours.

Thank you, as always.