[Solved]In Game Menus - Delete one option after executed

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.
Message
Author
User avatar
Mangescom
Newbie
Posts: 16
Joined: Sat Jul 04, 2015 1:45 pm
Deviantart: Mangescom
Contact:

[Solved]In Game Menus - Delete one option after executed

#1 Post by Mangescom »

Hi there!

I am looking for some way to hide menu options after they have been executed.

Take this for example:

Code: Select all

label start:
    
    menu:
        
        "'Do you like chocolate?'":
            jump chocolate
            
            
        "'How old are you?'":
            jump age
            
        
        "'You look weird...'":
            jump look
            
        "End conversation":
            return
            
            
label chocolate:
    "Mangescom""I am adicted to it!"
    jump start
    
label age:
    "Mangescom""My age? It's over 9000!"
    jump start
    
label look:
    "Mangescom""Well, thank you!"
    jump start
My goal:
After I asked "Do you like chocolate?" it is no longer available.
The same goes for all the other options untill you have only "End conversation" left.

I have tried to accomplish this with multiple rudiments but I kind of have no idea how to get that working.
Can anyone help me out?
Last edited by Mangescom on Sat Jul 04, 2015 4:44 pm, edited 2 times in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: In Game Menus - Delete one option after executed

#2 Post by xela »

Condition the menu choices with simple variables, there are many examples of this all over the forums.
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: In Game Menus - Delete one option after executed

#3 Post by trooper6 »

I'm going to give you the answer to your question, but also clean up your code to make it more elegant.

Code: Select all

 
label start:
    $ chocolate = True
    $ age = True
    $ look = True
    
    menu questions:
        "'Do you like chocolate?'" if chocolate:
            $chocolate = False
            "Mangescom""I am adicted to it!"
        "'How old are you?'" if age:
            $age = False
            "Mangescom""My age? It's over 9000!"
        "'You look weird...'" if look:
            $look = False
            "Mangescom""Well, thank you!"
        "End conversation":
            jump The_Next_Thing
    jump questions

label The_Next_Thing:
    "Everything is over"
    return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: In Game Menus - Delete one option after executed

#4 Post by Onishion »

If there's an elegant way to do it, I'd like to know as well, but the brute force approach would be to have variables that tick off.

Code: Select all

$ Option1 = 1
$ Option2 = 1
$ Option3 = 1

menu:
       
        "'Do you like chocolate?'" if Option1:
            $ Option1 = 0
            jump chocolate
           
           
        "'How old are you?'" if Option2:
            $ Option2 = 0
            jump age
           
       
        "'You look weird...'" if Option3:
            $ Option3 = 0
            jump look
           
        "End conversation":
            return
            
Now that will work, each time you pick an option, it would make it not show up the next time, but it's a bit clunky. You would need a separate variable for however many menu options you had at once, and if you reused them later you would need to reset them all to "1" or the new options would not show up. Again, if anyone has any better ideas, I'm all ears.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: In Game Menus - Delete one option after executed

#5 Post by SinnyROM »

What about keeping a list at the start to track chosen choices? I can't try it right now but it might look something like:

Code: Select all

init python:
    chosen = []

label start:
    menu:
        "One" if 'one' not in chosen:
            $ chosen.append('one')
        #...

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: In Game Menus - Delete one option after executed

#6 Post by Onishion »

Given how often Renpy uses menus, this might be a good place for a core function to be added. Something where you could just add "if once:" or something at the end of any menu option, and every time such a menu is called it automatically generates and increments the necessary variables like in our examples above, and then discards them afterwards.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: In Game Menus - Delete one option after executed

#7 Post by SinnyROM »

Onishion wrote:Given how often Renpy uses menus, this might be a good place for a core function to be added. Something where you could just add "if once:" or something at the end of any menu option, and every time such a menu is called it automatically generates and increments the necessary variables like in our examples above, and then discards them afterwards.
That would be great, something I'll find useful if any future projects call for it. It can make styling the buttons easier, and more complex logic that is already built in.

There is a variable with each choice, chosen, inside the choice screen. I haven't figured out how to use it yet though, nor if its purpose is for what we're looking for.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#8 Post by xela »

This might be a bit tricky... it's simpler to come up with functions like:

Code: Select all

default menc = set()
init python:
    def inmenc(arg):
        return not arg in menc
and use lines like:

Code: Select all

label menu_label:
    menu:
        "Meow" if inmenc("meow"):
             menc.add("meow")
             # Do something once...
it's easy to change set to a list and work with len() (+ one extra argument) build-in to check if we've been here once/x amount of times. What would be REALLY, REALLY useful if we could pass arguments from menu Ren'Py script statement to menu screen... that would give us some serious development power without resorting to sh!itty and confusing code based of analyzing strings or passing global variables and/or custom functions...
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#9 Post by trooper6 »

So...it turns out renpy already keeps track of chosen choices...so it is pretty trivial to set it up so that chosen choices don't show up. There is just one problem, this list is persistent...so replays result in no choices. I've figured out how to clear that particular persistent...so no problem there...but now I have to figure out how to keep one menu choice from staying off the list. Working on it...
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#10 Post by xela »

trooper6 wrote:So...it turns out renpy already keeps track of chosen choices...
This is sensible to assume since Rollback/Replay would require that to know the choices player made in order to roll back effectively or what to skip during replay. The trouble is that accessing that data is often difficult, confusing and requires not only very good knowledge of Python but also very deep knowledge of Ren'Py. Not mentioning that clearing (or interfering with) persistent or data (containing these choices) will very likely mess up how these systems function (unless something else was coded specifically for menus since I last checked).

Have fun taking a stab at it but you may end up with the conclusion that it is easier/more sensibe to work with custom functions and classes or string analysis until Ren'Py offers these options in way that is directly accessible or/and exposed to game developers...
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#11 Post by trooper6 »

Okay, I worked it out.
Now I spent a lot of time figuring out which big of information when where and looking in tuples...but in the end, I don't think that is necessary. So here is what I came up with. Two different options, both of which involve editing the screens.rpy file. It is important to note that these options are based off of using the persistent._chosen list that renpy uses to keep track of choices made. So...if you use this...you can't roll back and redo your choices (though I did find a way around that sort of.)
The other thing, if you want a choice to be choosable even after it has been chosen once (useful for those choices that break the menu loop, then you need to put an asterisk in its text.

So, option 1 will delete options that have already been chosen.

Code: Select all

screen choice(items):

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5
        vbox:
            style "menu"
            spacing 2

            for caption, action, chosen in items:
                #This keeps the options visible but no action if chosen
                #This deletes the options if chosen
                if not chosen or "*" in caption:
                    if action:
                        button:
                            action action
                            style "menu_choice_button"
                            text caption style "menu_choice"
                    else:
                        text caption style "menu_caption"
This second options will not delete the options, but will gray them out and make them unclickable:
screen choice(items):

Code: Select all

screen choice(items):

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5
        vbox:
            style "menu"
            spacing 2

            for caption, action, chosen in items:
                #This keeps the options visible but no action if chosen
                if action:
                    button:
                        if "*" in caption:
                            action action
                        else:
                            action If(chosen, true=None, false=action)
                        style "menu_choice_button"
                        text caption style "menu_choice"
                else:
                    text caption style "menu_caption"
Then in your script.rpy you just make your menus like so:

Code: Select all

    menu choices:
        "Do the Hokey-Pokey."
        "Put Your Right Foot In":
            "You put your right foot in."
        "Put Your Right Foot Out":
            "You put your right foot out."
        "Shake it All About":
            "You shake it all about."
        "*That's what it's all about.":
            "jump dance_over."
    jump choices
Of course if you ever return to this menu again, you won't be able to redo any of your done choices...even if you start a new game. Because...persistent.
You can wipe the persistent menu choices by using this command:
$persistent._chosen.clear()

But that will wipe menu choices for those people who want to auto skip past them with new games...and that might irritate some people.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#12 Post by xela »

Which is string analysis :) You can actually do a lot more with this by adding markers like (*, **, *** and clearing them when displaying choices display) and there is no need to mess with internals since you can use custom containers adding to them through actions as well.
It's not that big of a hassle, it's just a bit inconvenient and it would go a long way if we could parse extra args/kwargs from statement to screen directly, maybe even pick which screen to use.
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#13 Post by trooper6 »

xela wrote:Which is string analysis :) You can actually do a lot more with this by adding markers like (*, **, *** and clearing them when displaying choices display) and there is no need to mess with internals since you can use custom containers adding to them through actions as well.
It's not that big of a hassle, it's just a bit inconvenient and it would go a long way if we could parse extra args/kwargs from statement to screen directly, maybe even pick which screen to use.
How do you clear the ** when displaying the choices. I also think parsing extra args/kwargs into menus to screen would be amazing.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#14 Post by xela »

trooper6 wrote:How do you clear the ** when displaying the choices. I also think parsing extra args/kwargs into menus to screen would be amazing.
You remove them from the caption string before it is displayed.
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: [Solved]In Game Menus - Delete one option after executed

#15 Post by trooper6 »

xela wrote:
trooper6 wrote:How do you clear the ** when displaying the choices. I also think parsing extra args/kwargs into menus to screen would be amazing.
You remove them from the caption string before it is displayed.
So...you do that in the choice screen, yeah?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users