Nested if/else Statements in Ren'Py/Python?

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
Silence in Space
Regular
Posts: 31
Joined: Tue Nov 22, 2016 4:48 pm
Projects: Silence in Space
Contact:

Nested if/else Statements in Ren'Py/Python?

#1 Post by Silence in Space »

I am curious if the following is the correct way to right a nested if/else statement in Ren'Py using Python coding:

Code: Select all

$ fire_on = renpy.input("Yes/No?"):
	if fire_on == "Yes":
		jump turn_on_fire
	else:
		if fire_on == "yes":
			jump turn_on_fire
		else:
			if fire_on == "YES":
				jump turn_on_fire
			else:
				if fire_on == "No":
					jump leave_fire_off
				else:
					if fire_on == "no":
						jump leave_fire_off
					else:
						if fire_on "NO":
							jump leave_fire_off
						else:
							jump error_message1

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

Re: Nested if/else Statements in Ren'Py/Python?

#2 Post by Ocelot »

Correct way:

Code: Select all

if fire_on.lower() == "yes":
    jump turn_on_fire
elif fire_on.lower() == "no":
    jump leave_fire_off
else:
    jump error_message1
Docunmentation on .lower(): https://docs.python.org/3.4/library/std ... #str.lower
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot]