The syntax of operators [Solved]

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
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

The syntax of operators [Solved]

#1 Post by rinrin »

I was wondering whether there's an elegant way of listing multiple "or" conditions. Currently, I do it like this:

Code: Select all

if (month == 1) or (month == 3) or (month == 5) or (month == 7) or (month == 8) or (month == 10) or (month == 12):
...but that's really long. Is there a shorter way to write it? Why does the variable name (month) have to be repeated for every "or" (is there a way to state it just once?)
Last edited by rinrin on Mon Dec 14, 2009 11:15 pm, edited 1 time in total.

JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: The syntax of operators

#2 Post by JinzouTamashii »

Start here... http://wiki.python.org/moin/BeginnersGu ... rogrammers

May I humbly suggest http://www.pasteur.fr/formation/infobio/python/? This will be what I use to teach myself if I can't find a programmer for UDOU.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

User avatar
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

Re: The syntax of operators

#3 Post by rinrin »

Thank you, I'll take a look.

JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: The syntax of operators

#4 Post by JinzouTamashii »

I had it bookmarked, but it's at my work computer. Look for things dealing with operators and lists.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

Vorsic
Newbie
Posts: 18
Joined: Mon Mar 02, 2009 9:46 am
Contact:

Re: The syntax of operators

#5 Post by Vorsic »

What if you did something like

Code: Select all

$ possibleMonths = [1,3,5,7,8,10,12]
Then did

Code: Select all

if month in possibleMonths:
I haven't tried it, but I think it would work.

User avatar
rinrin
Veteran
Posts: 211
Joined: Thu Apr 16, 2009 9:18 am
Completed: Several.
Projects: Several.
Contact:

Re: The syntax of operators

#6 Post by rinrin »

I just tested it and it works!
Thank you!

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Majestic-12 [Bot]