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.
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#1
Post
by Exiscoming » Sat Mar 21, 2015 4:59 pm
Hey, quick (hopefully easy) question. How do I make an if statement activate if a variable is between 2 numbers? Example:
Code: Select all
if variable == 1-5:
"Hi, good to see you again!"
elif:
"Hello, I don't think we've met."
I know it's a dumb question, but I've been searching for over an hour, and simply don't know exactly what to look for.
Last edited by
Exiscoming on Mon Mar 23, 2015 3:13 pm, edited 1 time in total.
-
philat
- Eileen-Class Veteran
- Posts: 1853
- Joined: Wed Dec 04, 2013 12:33 pm
-
Contact:
#2
Post
by philat » Sat Mar 21, 2015 5:05 pm
Code: Select all
if 1 <= variable <=5:
"something"
else:
"something else"
You can also take out the = to have the comparison exclude the boundary numbers.
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#3
Post
by Exiscoming » Sat Mar 21, 2015 5:30 pm
Thank you! Is this the only way to do it though? I seem to have this idea that you could do something like:
Code: Select all
if variable == (1, 6):
"Something happeneds."
Not sure if I just misremember or maybe it's from another code language. It's been a long time since I've tried Ren'py.

-
Zetsubou
- Miko-Class Veteran
- Posts: 513
- Joined: Wed Mar 05, 2014 1:00 am
- Completed: See my signature
- Github: koroshiya
- itch: zetsuboushita
-
Contact:
#4
Post
by Zetsubou » Sat Mar 21, 2015 6:02 pm
Exiscoming wrote:Thank you! Is this the only way to do it though? I seem to have this idea that you could do something like:
Code: Select all
if variable == (1, 6):
"Something happeneds."
Not sure if I just misremember or maybe it's from another code language. It's been a long time since I've tried Ren'py.

Looks like it's from another language. In python, that statement says "if variable is equal to the tuple (1,6)", so it certainly isn't what you're looking for.
Maybe you're thinking of:
Code: Select all
if variable in range(1, 6):
"Something happeneds."
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails
Working on:
Sable's Grimoire 2

-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#5
Post
by Exiscoming » Sat Mar 21, 2015 6:04 pm
Maybe... either way it worked! Much obliged!
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#6
Post
by Exiscoming » Sun Mar 22, 2015 4:45 pm
Thanks again for the help, but I've stumbled upon another problem. Can I add an if statement inside of an if?
Example:
Code: Select all
if 0 >= morale <= 5:
"What?! No way!"
elif 6 >= morale <= 10:
$morale -= 1
$bobHomework += 1
"Fine I'll do it."
if 1 >= bobHomework <= 10:
"Bob looks dumb."
elif 11 >= bobHomework <= 20:
"Bob looks smart."
Right now it sometimes goes: "Bob looks smart." eventhough his bobHomework veriable is 1.
-
philat
- Eileen-Class Veteran
- Posts: 1853
- Joined: Wed Dec 04, 2013 12:33 pm
-
Contact:
#7
Post
by philat » Sun Mar 22, 2015 4:55 pm
Because all your comparisons are the wrong way. 1 <= variable <= 10, not 1 >= variable <= 10.
-
Alex
- Lemma-Class Veteran
- Posts: 2981
- Joined: Fri Dec 11, 2009 5:25 pm
-
Contact:
#8
Post
by Alex » Sun Mar 22, 2015 4:59 pm
Try
Code: Select all
if 1 <= bobHomework <= 10:
"Bob looks dumb."
elif 11 <= bobHomework <= 20:
"Bob looks smart."
edit: I'm soooo sloooo...
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#9
Post
by Exiscoming » Sun Mar 22, 2015 5:16 pm
Oh that's it! But wait, doesn't <= mean less or equal to?
Example:
if <= 10 Variable <= 20
"Activate!"
Doesn't this read as anything lower or equal to 10 and everything lower or equal to 20 will activate it?
Say that the variable is 9. That's lower than 10 and will therefor activate, right?
-
Zetsubou
- Miko-Class Veteran
- Posts: 513
- Joined: Wed Mar 05, 2014 1:00 am
- Completed: See my signature
- Github: koroshiya
- itch: zetsuboushita
-
Contact:
#10
Post
by Zetsubou » Sun Mar 22, 2015 5:20 pm
Exiscoming wrote:Oh that's it! But wait, doesn't <= mean less or equal to?
Example:
if <= 10 Variable <= 20
"Activate!"
Doesn't this read as anything lower or equal to 10 and everything lower or equal to 20 will activate it?
Say that the variable is 9. That's lower than 10 and will therefor activate, right?
You can't do that. What you're likely after is
Code: Select all
if 10 <= Variable <= 20:
"Activate!"
So if Variable is greater than or equal to 10, and less than or equal to 20, it's true.
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too, Sable's Grimoire, My Heart Grows Fonder, Man And Elf, A Dragon's Treasure
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers, Wolf Tails
Working on:
Sable's Grimoire 2

-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#11
Post
by Exiscoming » Sun Mar 22, 2015 5:25 pm
haha, thank you all for the help. I 'think' I get it now. And it seems to be working.

I'll probably come up with more questions in the future, but for now thanks!
Users browsing this forum: Bing [Bot]