if statement in choice? (another question)

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
junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

if statement in choice? (another question)

#1 Post by junna » Sun Sep 16, 2012 10:08 pm

Hi!

umm okay. I have a question...say

you have already encountered one choice
eg:

Code: Select all

menu: 
   "Left"
   "Right"
but you'll end up with having to pick a choice that is the same on both ends.
for 'left' and 'right' choice.

Code: Select all

menu:
  "sink"
  "swim"
However, it is based on your earlier choice (left/right) that defines which set of the next options (different sets of choices for "sink" and "swim" unlike the same "sink" or "swim" choice for "left" and "right") you'll encounter.

Is there an easy way for me to say in code which menu is to come out? Or do I have to separate it oune by one?
Last edited by junna on Tue Sep 25, 2012 10:01 am, edited 2 times in total.
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

User avatar
Minnfae
Regular
Posts: 106
Joined: Mon Dec 07, 2009 5:01 am
Projects: Undecided
Contact:

Re: if statement in choice? (maybe)

#2 Post by Minnfae » Sun Sep 16, 2012 10:15 pm

maybe you can use a list? I'll write some code, wait a bit.

EDIT:
here's what I think you wanted to do:

Code: Select all

label start:
    #left is 1, right is 2, correct_path defines the right path, if the player chooses a different one he has to start over
    #the correct path in this one is left, left, right, left, left, left, right
    $ correct_path=[1,1,2,1,1,1,2]
    $ numberofsteps=0
    jump maze

label maze:
    if numberofsteps==len(correct_path):
        jump mazeend
    menu: 
        "Left":
            "I go to the left"
            if correct_path[numberofsteps]==1:
                $ numberofsteps+=1
                jump maze
            else:
                jump mazefail
        "Right":
            "I go to the right"
            if correct_path[numberofsteps]==2:
                $ numberofsteps+=1
                jump maze
            else:
                jump mazefail
label mazefail:
    "fail"
    "start over"
    $ numberofsteps=0
    jump maze

label mazeend:
    "YOU WIN!!"
EDIT 2:
Oops, I didn't read it completely, if you want to make different choices available or not depending on the previous choose, you may make them depend on the number of steps. For example, if you want to make it possible for the steps number 4 and 6, you make an if statement that looks like:

Code: Select all

if numberofsteps in [4,6]
Last edited by Minnfae on Sun Sep 16, 2012 10:33 pm, edited 1 time in total.
My avatar art is a freebie by SilverHyena. Thanks a lot!

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: if statement in choice? (maybe)

#3 Post by kankan » Sun Sep 16, 2012 10:31 pm

Err...if I understand correctly, you want to have only two menus, where the options in the second menu change depending on the choice made in the first menu? You can do that with if statements if you really want to, but depending on how complicated the menus are it might be simpler to just separate the second menu into two (without if statements). But if it's not too complicated, then something like this, maybe?

Code: Select all

menu:
    "Which way should I go?"
    "Right!":
        $path = 'right'
        jump path1
    "Left!":
        $path = 'left'
        jump path2

...

menu2:
    "Should I cross the river?"
    "I can jump it!" if path == 'right':
        jump path1fail
    "I can jump it!" if path == 'left':
        jump path2success

...

User avatar
junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

Re: if statement in choice? (maybe)

#4 Post by junna » Mon Sep 17, 2012 2:13 am

0_0 ooh.. two options. I'll try both and see if any of these comes out the way I'd want to.
*I shall kill you, you evil programme language you*
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

User avatar
junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

Re: if statement in choice? (maybe)

#5 Post by junna » Tue Sep 18, 2012 8:40 pm

since the story is like this
path.png
path.png (10.73 KiB) Viewed 513 times
I had a better result using kankan's suggestion!

Thanks to both for your help!
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

User avatar
junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

Re: if statement in choice? (another question)

#6 Post by junna » Tue Sep 25, 2012 10:06 am

hi

I'm trying to display 2 different menu choice based on a previous decision.
'Count' or 'change'

So I thought it would look like this.

Code: Select all

menu:
        t "{i}Now{/i} what should I do?"
            
        if  path == 'Count'
        
            "{color=#ffffff}Swing{/color}":
                jump Swing
            
            "{color=#ffffff}Jerk{/color}":
                jump Jerk
            
        
        else path == 'Change':
        
            "{color=#ffffff}Metal{/color}":
                jump Metal
            
            "{color=#ffffff}Silver{/color}":
                jump Silver
^^;; apparently not. Could someone help me repair this?
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

User avatar
Camille
Eileen-Class Veteran
Posts: 1227
Joined: Sat Apr 23, 2011 2:43 pm
Completed: Please see http://trash.moe
Projects: the head well lost
Organization: L3
Tumblr: narihira
Deviantart: crownwaltz
itch: lore
Contact:

Re: if statement in choice? (another question)

#7 Post by Camille » Tue Sep 25, 2012 11:02 am

Should be like this:

Code: Select all

menu:
        t "{i}Now{/i} what should I do?"
                            
        "{color=#ffffff}Swing{/color}" if path == 'Count':
            jump Swing
            
        "{color=#ffffff}Jerk{/color}" if path == 'Count':
            jump Jerk
               
        "{color=#ffffff}Metal{/color}" if path == 'Change':
            jump Metal
            
        "{color=#ffffff}Silver{/color}" if path == 'Change':
            jump Silver

User avatar
junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

Re: if statement in choice? (another question)

#8 Post by junna » Tue Sep 25, 2012 7:42 pm

ahh... thank you!

I think my brain just trolled itself
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot, zyric