Multiple if statements into one?

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
searchwindows
Regular
Posts: 68
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Multiple if statements into one?

#1 Post by searchwindows » Thu Apr 14, 2022 4:07 am

This seems like a basic one but I forgot how it was done...
I'll go ahead and show you what I'm trying to achieve.

Here's an example of a normal way.

Code: Select all

default hour = 0
if hour ==  1:
	call screen room_1_screen
elif hour == 2:
	call screen room_2_screen
elif hour == 3:
	call screen room_3_screen
elif hour == 4:
	call screen room_4_screen
So by the above code if I were to create up to 10 hours, I'd had to write it down one by one until the tenth hour.
If I were to have up to 50 hours, writing that will require 50 if statements which sounds inefficient.

Is it possible to turn all that into one if statement?
I'd assume I'd have to create a function. And I'd call the function to make the hour pass and by doing that, "room_x_screen", x would go up as well.
I don't know where to start!
Sorry for the hideous explanation..

Xiael
Regular
Posts: 31
Joined: Thu Aug 06, 2020 9:13 am
itch: Xiael
Discord: message me first here
Contact:

Re: Multiple if statements into one?

#2 Post by Xiael » Thu Apr 14, 2022 4:35 am

Try something like this

Code: Select all

screen room(hour):
  text "time elapsed: [hour]"
and call by:

Code: Select all

call screen room(1)

But I can't confirm it because I'm not with my computer right now tho
Anime sprite commissions $30 per character: viewtopic.php?f=62&t=60703&p=536689#p536689

Post Reply

Who is online

Users browsing this forum: Google [Bot]