Multiple AND conditions?

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
tcassat
Newbie
Posts: 18
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Multiple AND conditions?

#1 Post by tcassat » Wed Dec 13, 2017 10:34 am

Hello.

Is it possible to use multiple AND conditions on the same line? I would like an option to appear in a menu if three conditions were met: x >3, y is true and z is false:

It works with two conditions:

menu:
"Option A" if x>3 and y

But if I need another "and", things will not work out.

menu:
"Option A" if x>3 and y and not z


Note that I need to write everything on the same line because it is a menu option. Can you use multiple "and" and "or" or do I have to do it any other way?

User avatar
RicharDann
Regular
Posts: 120
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Multiple AND conditions?

#2 Post by RicharDann » Wed Dec 13, 2017 10:45 am

Yes, using multiple conditions that way should work. Are you sure that you're using the correct syntax?

Code: Select all

    menu:
        "Option A" if x > 3 and y and not z:
            "You picked A"

tcassat
Newbie
Posts: 18
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Re: Multiple AND conditions?

#3 Post by tcassat » Wed Dec 13, 2017 10:56 am

Yes, it worked, I had made a ridiculous mistake in the name of the variable (it was not as simple as "y"). I think the moderator can delete this topic!

User avatar
Remix
Veteran
Posts: 492
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet
Projects: An un-named 3d anime based trainer game
Contact:

Re: Multiple AND conditions?

#4 Post by Remix » Wed Dec 13, 2017 11:52 am

Just for info, you can use all( list of tests ) and/or any( list of tests ) in a menu...

Code: Select all

    menu:
        "ok 1" if all( [ True, 1, len("a") ] ):
            "..."
        "ok 2" if any( [ True, 0, len("") ] ):
            "..."
        "bad 1" if all( [ False, 1, len("a") ] ):
            "..."
        "bad 2" if any( [ False, 0, len("") ] ):
            "..."

Post Reply

Who is online

Users browsing this forum: No registered users