Conditional Menu Items

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
Swinwappy
Newbie
Posts: 14
Joined: Mon Jun 01, 2020 3:52 am
Contact:

Conditional Menu Items

#1 Post by Swinwappy »

Hi,

I have a menu that hides certain options based on clock.time and whether or not that person is alive:

Code: Select all

menu:
	"Casey" if caseyAlive == 1 and clock.time=="8AM", "9AM", "10AM", "5PM", "6PM", "7PM", "8PM":
		jump Casey
	"not casey":
		pass
It seems like the menu won't recognise any variables if I have the "and" in there, so using this code "Casey" would show as a Menu item even at 11AM if she's dead.

If I remove the caseyAlive variable, the time element works and she only shows up at the correct times. If I remove the time variable, she only shows up if she's alive.

Does anyone know why this is happening? Thanks.

User avatar
m_from_space
Miko-Class Veteran
Posts: 974
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Conditional Menu Items

#2 Post by m_from_space »

Your syntax with the clock.time is wrong, where did you get that from? :D

Code: Select all

    menu:
        "Casey" if caseyAlive == 1 and clock.time in ["8AM", "9AM", "10AM", "5PM", "6PM", "7PM", "8PM"]:
            jump Casey
        "not casey":
            pass
If I remove the caseyAlive variable, the time element works and she only shows up at the correct times.
I don't believe you here by the way.

Swinwappy
Newbie
Posts: 14
Joined: Mon Jun 01, 2020 3:52 am
Contact:

Re: Conditional Menu Items

#3 Post by Swinwappy »

m_from_space wrote: Wed May 25, 2022 1:07 am Your syntax with the clock.time is wrong, where did you get that from? :D

Code: Select all

    menu:
        "Casey" if caseyAlive == 1 and clock.time in ["8AM", "9AM", "10AM", "5PM", "6PM", "7PM", "8PM"]:
            jump Casey
        "not casey":
            pass

I'm very new to python. I made it myself :D

Thanks for this, mate!

User avatar
m_from_space
Miko-Class Veteran
Posts: 974
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Conditional Menu Items

#4 Post by m_from_space »

Swinwappy wrote: Wed May 25, 2022 1:10 am I'm very new to python. I made it myself :D

Thanks for this, mate!
It's actually renpy script which created the confusion, because python would have thrown a syntax error. If you want to compare multiple things in python you have to write the following.

Code: Select all

if a == 1 or a == 2 or a == 3:
or

Code: Select all

# check if a is an element inside the list [1, 2, 3]
if a in [1, 2, 3]:

Post Reply

Who is online

Users browsing this forum: Google [Bot], Karrion, Nozori_Games, voluorem