Conditional Menu Options?

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
starling_harley
Newbie
Posts: 6
Joined: Wed Sep 21, 2022 8:25 pm
Projects: The Diamandian Guard
Deviantart: m5w
Location: yeehawland
Discord: starlitseas#2253
Contact:

Conditional Menu Options?

#1 Post by starling_harley »

Howdy all! I'm having some issues with (presumably?) my labels and calling to them? Or, at least trying to make my options hidden after clicking on them. I've been using [https://www.renpy.org/wiki/renpy/doc/tu ... er_Choices]this piece of documentation[/url] as reference, but I may be misunderstanding something within it. :oops:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 308, in script
    menu:
  File "game/script.rpy", line 309, in <module>
    "About Melanie." if about_melanie == False:
NameError: name 'about_melanie' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 308, in script
    menu:
  File "renpy/ast.py", line 1628, in execute
    choice = renpy.exports.menu(choices, self.set, args, kwargs, item_arguments)
  File "renpy/exports.py", line 965, in menu
    condition = renpy.python.py_eval(condition)
  File "renpy/python.py", line 2135, in py_eval
    return py_eval_bytecode(code, globals, locals)
  File "renpy/python.py", line 2128, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/script.rpy", line 309, in <module>
    "About Melanie." if about_melanie == False:
NameError: name 'about_melanie' is not defined

And here's the code I'm currently working with for the whole dealie.

Code: Select all


    ##CLICKABLECARRIAGE START##
    scene movingcarriagebg:
        carriagesway
    show carriageclickablemelanie smile
    show screen melcarriage

    show carriageclickablemelanie smiletalk
    carriagemel "I'm so happy we get to live here now!"
    show carriageclickablemelanie smile
    carriagemel "I'm also a little nervous, of course, but I bet you're nervous too!"

    tip "TUTORIAL: Sometimes there are clickables in the environment!"
    tip "Try clicking on the curtains to see what happens!"

    pause

    label movethecurtain:
        show movingcurtains
        hide screen melcarriage
        show carriageclickablemelanie neutral
        carriagemel "Aww... That's okay."
        show carriageclickablemelanie smile
        carriagemel "At least that confirms my suspiscions about you being nervous, though!"
        carriagemel "You wanna talk about something else?"

        jump .carriagedefault

        label .carriagedefault:

            menu:
                "About Melanie." if about_melanie == False:
                    $ about_melanie = True
                    jump .carriageABOUTMELANIE

                "About Melanie's family." if about_melanie == True:
                     $ melfam = True
                     jump .carriageMELFAM
                                  
                "About the area." if areaask == False:
                  jump .carriageAREA
                  $ areaask = True

                "Who's driving?" if driverkundone == False:
                    $ driverkundone = True
                    jump .driverkun

                "Is that so...?" if melanie_affection > 3:
                    jump carriageout

        label .carriageABOUTMELANIE:
            show carriageclickablemelanie bashfultalk
            carriagemel "Shucks, I didn't think I'd be so interesting!"
            show carriageclickablemelanie smile
            carriagemel "I'm personally here because my sister works at the castle."
            show carriageclickablemelanie neutraltalk
            carriagemel "She's the Royal Architect! Can you {i}imagine?{/i}"
            show carriageclickablemelanie smiletalk
            carriagemel "I personally couldn't imagine being responsible for the whole darn structure of that big ol' palace down there!"
            show carriageclickablemelanie smiletalk2
            cn "Melanie giggles a bit and smiles at you."
            show carriageclickablemelanie smile
            carriagemel "I'm really happy she's got a cushy job now! Especially because she's so reliable and smart!"
            show carriageclickablemelanie smile2
            cn "Melanie sighs a bit wistfully."
            show carriageclickablemelanie smile
            carriagemel "Mama and Papa were totally wrong about her after she left..."

            $ melanie_affection += 1

            jump .carriagedefault
        
        label .carriageAREA:
            show carriageclickablemelanie smile
            carriagemel "I don't know much about Lustrenia other than that it's the capitol of Diamandis!"
            show carriageclickablemelanie bashful
            carriagemel "I'm not very good at geography or just learning about places in general..."

            $ melanie_affection += 1

            jump .carriagedefault
       
        label .driverkun:
            show carriageclickablemelanie smiletalk
            carriagemel "Oh, that's just Henri!"
            show carriageclickablemelanie smile
            carriagemel "He's a pretty nice guy - REALLY good with horses!"
            show carriageclickablemelanie bashful
            carriagemel "Don't tell him, but I actually kinda think he's pretty cute!"

            $ melanie_affection += 2

            jump .carriagedefault

        label .carriageMELFAM:
            show carriageclickablemelanie smiletalk
            carriagemel "Oh! I grew up with my older sister on my parents' farm!"
            show carriageclickablemelanie smile2
            carriagemel "It was pretty peaceful growing up, especially since none of us really had any talent for magic."
            show carriageclickablemelanie neutraltalk
            carriagemel "Oh! Except for Bella!"
            carriagemel "She was always really good at art and stuff, so I guess one day it turned into magic!"
            show carriageclickablemelanie smile
            carriagemel "Teachers at school were always calling her a prodigy! And Mama and Papa were proud, too..."
            show carriageclickablemelanie neutral
            cn "Melanie's smile fades, and she seems contemplative."
            carriagemel "But... Mm. As it stands right now, I'm not. On really good terms with my parents..."
            carriagemel "Ever since the war Diamandis had over Polgalla, they pretty much disowned Bella for joining up with the Diamandians."
            carriagemel "Even after she became this super accomplished sculptor and got continentally famous, everyone turned against her..."
            show carriageclickablemelanie miffedtalk
            carriagemel "Which is unfair to her because it's not her fault she got swept up into that whole mess!"
            show carriageclickablemelanie miffed
            carriagemel "..."
            show carriageclickablemelanie neutraltalk
            carriagemel "Anyway, I'm here to support her 'cause our parents aren't. She's probably been so lonely without me!"
            show carriageclickablemelanie smile

            $ melanie_affection += 1

            jump .carriagedefault

    ##CLICKABLECARRIAGE END##
Thank y'all in advance for helping me out! :D

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Conditional Menu Options?

#2 Post by Ocelot »

What is the value of about_melanie when menu is first reached? To be precise, where is the code which sets that value? You have to set variable to something, before you check it.
< < insert Rick Cook quote here > >

User avatar
starling_harley
Newbie
Posts: 6
Joined: Wed Sep 21, 2022 8:25 pm
Projects: The Diamandian Guard
Deviantart: m5w
Location: yeehawland
Discord: starlitseas#2253
Contact:

Re: Conditional Menu Options?

#3 Post by starling_harley »

Oh! I set the labels to False at the beginning of my code (after the label start line of code) to keep things organized. So the values technically exist as such--

Code: Select all

label start:

    [affection value stuff]

    $ about_melanie = False
    $ melfam = False
    $ areaask = False
    $ driverkundone = False
But it's just not reading it for some reason? At least, that's what I'm seeing. (Sorry for not putting this in the main post initially, by the way. (;´д`)ゞ)

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Conditional Menu Options?

#4 Post by enaielei »

The problem with how you set your variables is that it only gets set if the start label is reached. So if somehow you managed to skip the start label and jumped right into the label where these variables are being used, then that would be an error since the variables never got defined.
Have a look at defaulting your variables: https://www.renpy.org/doc/html/python.h ... -statement

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Conditional Menu Options?

#5 Post by _ticlock_ »

starling_harley wrote: Tue Oct 25, 2022 11:06 am Oh! I set the labels to False at the beginning of my code (after the label start line of code) to keep things organized. So the values technically exist as such--
But it's just not reading it for some reason? At least, that's what I'm seeing. (Sorry for not putting this in the main post initially, by the way. (;´д`)ゞ)
EDIT: enaielei already answered the question (while I was writing response).

Initialize the variable with default statements outside labels:

Code: Select all

default about_melanie = False
default melfam = False
default areaask = False
default driverkundone = False

label start:

Last edited by _ticlock_ on Tue Oct 25, 2022 1:45 pm, edited 3 times in total.

User avatar
starling_harley
Newbie
Posts: 6
Joined: Wed Sep 21, 2022 8:25 pm
Projects: The Diamandian Guard
Deviantart: m5w
Location: yeehawland
Discord: starlitseas#2253
Contact:

Re: Conditional Menu Options?

#6 Post by starling_harley »

Yooo, that fixed it! Thank you so much! ヾ(• 7 •`)o

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]