bracnching and remembering previous choice problem

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
The Monkey Ninja
Regular
Posts: 34
Joined: Mon Jul 05, 2010 5:06 pm
Projects: 3^07, OneTimeValentine, OtomeDesign
Organization: MooseCake Productions
Deviantart: the-monkey-ninja
Location: South Africa
Contact:

bracnching and remembering previous choice problem

#1 Post by The Monkey Ninja » Tue Jul 06, 2010 11:45 am

Ok, i'm new here, and to using renpy, so sorry if this is a silly question ^^;
but i'm having problems with the memorizing of the user's choices, and branching the game based on them. Um, here's an example of what i mean (note that its not the actual script, just similar in the way i bracnched everything...)
Eg:

e "I'm gonna do a test! K?"

menu:

"Apologize":
jump sorry

"Ignore":
jump ignore

label sorry:

$ sorry_option = "Apologize"

a "I'm sorry, i shouldn't have yelled like that."
s "...it's okay. I was in the wrong too."
jump test

label ignore:

$ ignore = "Ignore"

a "..."
s "Hey! Apologize!"
a "Hmph!"
jump test

label test:

t "So what happened?"

if sorry_option == "Apologize":

a "The problem was resolved and we're friends again!"
t "Ahaha, that's good."
jump distance

elif ignore == "Ignore":

a "I ingored her. She was the one at fault."
t "Oh..."
jump argue

(sorry, i just pasted the text here. all the spacing is done right in the script.)
The error was that the "'sorry_option' is not defined"
if you choose to apologize, it runs smoothly, but when you choose ignore, that error comes up (and the same if there is a third option as well).
I wonder if anyone knows what i'm doing wrong? Or if i've missed something in the coding???

Please help! Thanks so much... =D

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: bracnching and remembering previous choice problem

#2 Post by Jake » Tue Jul 06, 2010 11:49 am

The Monkey Ninja wrote:

Code: Select all

    $ ignore = "Ignore"
The error was that the "'sorry_option' is not defined"
It's because you're not setting the 'sorry_option' variable when you choose to ignore, but rather one called 'ignore'.

(As an aside, if you post bits of code, it's a good idea to wrap them in 'code' tags - there's a button for it in the editor - which preserves the spacing properly.)
Server error: user 'Jake' not found

User avatar
The Monkey Ninja
Regular
Posts: 34
Joined: Mon Jul 05, 2010 5:06 pm
Projects: 3^07, OneTimeValentine, OtomeDesign
Organization: MooseCake Productions
Deviantart: the-monkey-ninja
Location: South Africa
Contact:

Re: bracnching and remembering previous choice problem

#3 Post by The Monkey Ninja » Tue Jul 06, 2010 12:02 pm

But if i put the 'sorry_option' variable in, won't that make the story progress as if the player had selected the 'Apologize' option rather than the 'Ignore' option?

(ps: thanks! i'll use that next time =) )

User avatar
CaesMRaenes
Regular
Posts: 132
Joined: Wed Aug 19, 2009 12:42 am
Projects: 軽い夏, The Aces
Contact:

Re: bracnching and remembering previous choice problem

#4 Post by CaesMRaenes » Tue Jul 06, 2010 12:22 pm

I don't know if it's my place to answer your second question so excuse me ahead of time.

The best example I can think of to help you understand the way your variables are working is this:
I have hands but you have to choose either my left or my right. So my variable name would be "hands" ($ hands). If you choose left, my "hands" would equal "left" ($ hands = "left"). If you choose right, my "hands" would equal "right" ($ hands = "right").

So for your options, you're making a variable that would apply to one situation but have different options. Because you have the options reappear later, it'll trigger your events depending on what option line passed through. Like for my example:

if hands == "left":
me "I'm going to pet your hair."

elif hands == "right":
me "I'm going to knock your brains out."

I hope this helps even a little bit to see why you have one variable name for two different options.
a.k.a. DragonfaeryYume on dA
The Vault in the Sky (Dev Blog)

Projects:
WIP The Aces
WIP (Head Artist) 軽い夏: The Sun Will Shine Through (tentative title)

User avatar
The Monkey Ninja
Regular
Posts: 34
Joined: Mon Jul 05, 2010 5:06 pm
Projects: 3^07, OneTimeValentine, OtomeDesign
Organization: MooseCake Productions
Deviantart: the-monkey-ninja
Location: South Africa
Contact:

Re: bracnching and remembering previous choice problem

#5 Post by The Monkey Ninja » Fri Jul 09, 2010 7:17 am

Yes, it helps quite a bit actually, thanks! :D
I see, since it had the same label there, it confused the system a bit, so i changed it to something like this:

Code: Select all

label sorry:
    
    $ sorry_option = "Apologize"
    
    a "I'm sorry, i shouldn't have yelled like that."
    s "...it's okay. I was in the wrong too."
    jump test   
    
label ignore:
           
    $ ignore_option = "Ignore"
        
    a "..."
    s "Hey! Apologize!"
    a "Hmph!"
    jump test_1
    
label test:

    t "So what happened?"

    if sorry_option == "Apologize":
       
        a "The problem was resolved and we're friends again!"
        t "Ahaha, that's good."
        jump distance
               
label test_1:        
        
    if ignore_option == "Ignore":

        a "I ignored her. She was the one at fault."
        t "Oh..."
        jump argue
and it works fine now! =D
Thanks for the help~! XD
--
Cloaks are wonderful things~ <3

My DA page for all my art:
http://the-monkey-ninja.deviantart.com/

Ex-Nanoreno2017 game One Time Valentine has a (very rough) demo out now!
viewtopic.php?f=43&t=43314

Post Reply

Who is online

Users browsing this forum: Bing [Bot], _ticlock_