Remebering Selected Choices.

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
ShippoK
Veteran
Posts: 348
Joined: Wed Mar 28, 2012 8:59 pm
Projects: Eyes of Gold (In-Progress)
Organization: (Red Moon)
Location: Glorious Nippon (A.K.A the USA)
Contact:

Remebering Selected Choices.

#1 Post by ShippoK » Thu Oct 24, 2013 8:00 pm

I was having a hard time finding any info on this so I'll just ask on the Q&A thread.

I was wondering if there was a simple way to have menu choices that a player made in a previous game be remember for the rest of the game.
Something along the lines of this.
Ex.
Image

Here's the menu choice code if needed.

Code: Select all

    style.menu_choice_button.background = Frame("menuchoicevr.1.png",25,15)
    style.menu_choice_button.hover_background = Frame("menuchoicevr.2.png",25,15)
    style.menu_choice_button.yminimum = 40
    style.menu_choice_button.xminimum = 375
Much Appreciated for those who took the Survey!

Image Image
Eyes of Gold [BL (Suspense) (+18)] IN-PROGRESS
Alternate Online [(Friendship) (+10)] ON-HOLD
DeviantART• •[Honest critique] - 'Honesty is its own reward.'

User avatar
SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: Remebering Selected Choices.

#2 Post by SundownKid » Thu Oct 24, 2013 8:16 pm

You could give each choice its own variable and then modify that choice depending on if it's true or false.

Code: Select all

menu:
  if persistent.choice1 == True:
     "{color=#EAF00}Do stuff{/color}":
        jump choice1
  else:
      "Do stuff":
         $ persistent.choice1 = True
         jump choice1

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Remebering Selected Choices.

#3 Post by Elmiwisa » Thu Oct 24, 2013 8:41 pm

No need, Ren'Py do it for you. Except not completely.
Look at the code for the choice screen in screens.rpy. You will find this line:

Code: Select all

for caption, action, chosen in items:
A careful reading of the code will reveal that while variable caption and action will be referred to after this line, variable chosen is never used. That unused variable mark which choice have been made before, and is persistent. You simply need to modify the code to make use of this variable. Something like:

Code: Select all

if chosen:
    #one kind of button
else:
    #another kind of button

User avatar
ShippoK
Veteran
Posts: 348
Joined: Wed Mar 28, 2012 8:59 pm
Projects: Eyes of Gold (In-Progress)
Organization: (Red Moon)
Location: Glorious Nippon (A.K.A the USA)
Contact:

Re: Remebering Selected Choices.

#4 Post by ShippoK » Thu Oct 24, 2013 9:17 pm

Thank you for the answers.

I'll probably do ShundownKid's method for now.
When I feel more comfortable with fiddling with the code Elmiwisa mentioned above, I'll try that one out as well.
Much Appreciated for those who took the Survey!

Image Image
Eyes of Gold [BL (Suspense) (+18)] IN-PROGRESS
Alternate Online [(Friendship) (+10)] ON-HOLD
DeviantART• •[Honest critique] - 'Honesty is its own reward.'

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Remebering Selected Choices.

#5 Post by Elmiwisa » Fri Oct 25, 2013 2:29 am

ShippoK wrote:Thank you for the answers.

I'll probably do ShundownKid's method for now.
When I feel more comfortable with fiddling with the code Elmiwisa mentioned above, I'll try that one out as well.
Uh, it's a pretty simple change that take less than 5 minutes, and once done it apply instantly to all menu. It's much less painful than doing it individually for each menu. I can't really tell you exactly how to make the change, because it depends on how you want your menu to look like. Though this is one simple way to do it:
Replace all the choice screen code with this:

Code: Select all

screen choice:

    window: 
        style "menu_window"        
        xalign 0.5
        yalign 0.5
        
        vbox:
            style "menu"
            spacing 2
            
            for caption, action, chosen in items:
                
                if action:  
                    if chosen:
                        button:
                            action action
                            style "menu_choice_chosen_button"                        

                            text caption style "menu_choice_chosen"
                    else:
                        button:
                            action action
                            style "menu_choice_button"                        

                            text caption style "menu_choice"
                    
                else:
                    text caption style "menu_caption"

Then just make your style for "menu_choice_chosen" and "menu_choice_chosen_button". Pretty simple change really, it's less than 20 extra lines from the original default Ren'Py code.
Beside, SundownKid's method don't even work. You need to modify it due to syntax error.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Ocelot