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.
-
Team1Player2
- Newbie
- Posts: 9
- Joined: Tue Mar 29, 2022 4:01 am
-
Contact:
#1
Post
by Team1Player2 » Sun Sep 04, 2022 1:45 pm
Hello,
my game revolves around a day-night loop. I want to display the time to the player while progressing and resetting the time.
My current solution is to
a) set up a variable that is just a number
b) increase and set it back to zero as the day progresses
Code: Select all
$ day_phase += 1
if day_phase == 4:
$ day_phase = 0
c) and finally display a message to the player
Code: Select all
screen day_phase_screen():
if day_phase == 0:
text "Morning"
elif day_phase == 1:
text "Noon"
elif day_phase == 2:
text "Afternoon"
elif day_phase == 3:
text "Evening"
else:
text "Night"
This works but I find it weird for some reason.
Is there a way to streamline this? I tried making a dictionary with number:phase pairs but couldn't figure out how to progress the time and display the new time on the custom screen. Am I just overthinking this and should be content with my current solution?
Last edited by
Team1Player2 on Sun Sep 04, 2022 3:55 pm, edited 1 time in total.
-
Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#2
Post
by Ocelot » Sun Sep 04, 2022 2:25 pm
First step of removing redundant code - shove it in function:
Code: Select all
default day_phase = 0
define day_phase_descriptions = {
0: _("Morning"),
1: _("Noon"),
2: _("Afternoon"),
3: _("Evening"),
4: _("Night"),
}
init python:
def advance_time():
store.day_phase += 1
if store.day_phase > 4:
store.day_phase = 0
# . . .
screen day_phase_screen():
text day_phase_descriptions[day_phase]
# . . .
"Time passes"
$ advance_time()
Ideally you would wrap all that into class, but currently it is not strictly nessesary.
< < insert Rick Cook quote here > >
-
Team1Player2
- Newbie
- Posts: 9
- Joined: Tue Mar 29, 2022 4:01 am
-
Contact:
#3
Post
by Team1Player2 » Sun Sep 04, 2022 4:04 pm
Thank you so much. I implemented your solution and it works flawlessly.
In the end, I made some tweaks to expand the functionality a little bit further.
Code: Select all
default day_count = 0
default day_phase = 0
define day_phase_descriptions = {
0: _("Morning"),
1: _("Noon"),
2: _("Afternoon"),
3: _("Evening"),
4: _("Night"),
}
init python:
def advance_time():
store.day_phase += 1
if store.day_phase > 4:
store.day_phase = 0
store.day_count += 1
# . . .
screen day_phase_screen():
text "Day: [day_count], " + day_phase_descriptions[day_phase]
# . . .
"Time passes"
$ advance_time()
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]