How to change main menu screen according to system time?
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.
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.
-
Alvsvartr
- Newbie
- Posts: 20
- Joined: Wed Aug 17, 2016 9:31 am
- Soundcloud: nebelwand-ua
- Location: Ukraine
- Contact:
How to change main menu screen according to system time?
Hi all,
So basically, I plan to change the main menu background four times a day:
- from 6:00 AM to 11:00 AM - the first image
- from 11:00 AM to 06:00 PM - the second image
- from 06:00 PM to 09:00 PM - the third image
- from 09:00 PM to 06:00 AM - the fourth image
It doesn't look like an utterly impossible task, yet I have no particular idea.
Could you please help me with how I can achieve this? Thanks.
So basically, I plan to change the main menu background four times a day:
- from 6:00 AM to 11:00 AM - the first image
- from 11:00 AM to 06:00 PM - the second image
- from 06:00 PM to 09:00 PM - the third image
- from 09:00 PM to 06:00 AM - the fourth image
It doesn't look like an utterly impossible task, yet I have no particular idea.
Could you please help me with how I can achieve this? Thanks.
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: How to change main menu screen according to system time?
Since Renpy is in symbiosis with Python, you can just use Python to get the current time via the datetime module. Format it to your needs and then change your main_menu screen according to the variable.
Code: Select all
init python:
from datetime import datetime
screen main_menu():
python:
time_object = datetime.now()
time_hours = int(time_object.strftime("%H"))
time_minutes = int(time_object.strftime("%M"))
if time_hours >= 6 and time_hours < 11:
...
-
Alvsvartr
- Newbie
- Posts: 20
- Joined: Wed Aug 17, 2016 9:31 am
- Soundcloud: nebelwand-ua
- Location: Ukraine
- Contact:
Re: How to change main menu screen according to system time?
Thank you for your reply.m_from_space wrote: ↑Sat Aug 20, 2022 8:58 amSince Renpy is in symbiosis with Python, you can just use Python to get the current time via the datetime module. Format it to your needs and then change your main_menu screen according to the variable.
I'm trying to use it correctly, but it doesn't want to work fine.
So, as the first step, I changed gui.rpy in the following way (I'm not sure in it):
Code: Select all
define gui.main_menu_background = ["images/start1.png", "images/start2.png", "images/start3.png", "images/start4.png"]
Code: Select all
init python:
from datetime import datetime
screen main_menu():
python:
time_object = datetime.now()
time_hours = int(time_object.strftime("%H"))
time_minutes = int(time_object.strftime("%M"))
if time_hours >= 6 and time_hours < 11:
show start1
if time_hours >= 11 and time_hours < 18:
show start2
if time_hours >= 18 and time_hours < 21:
show start3
if time_hours >= 21 and time_hours < 6:
show start4
Be so kind as to help me. Thanks.
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: How to change main menu screen according to system time?
No, please revert that, we won't need that config variable, since we replace it anyway. Also you cannot just put a list of strings there and hope it will do something.Alvsvartr wrote: ↑Sat Aug 20, 2022 11:44 amSo, as the first step, I changed gui.rpy in the following way (I'm not sure in it):Code: Select all
define gui.main_menu_background = ["images/start1.png", "images/start2.png", "images/start3.png", "images/start4.png"]
Code: Select all
define gui.main_menu_background = None
Code: Select all
init python:
from datetime import datetime
screen main_menu():
tag menu
style_prefix "main_menu"
python:
time_object = datetime.now()
time_hours = int(time_object.strftime("%H"))
if time_hours >= 6 and time_hours < 11:
add "start1"
elif time_hours >= 11 and time_hours < 18:
add "start2"
elif time_hours >= 18 and time_hours < 21:
add "start3"
else:
add "start4"
use navigation
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
- Contact:
Re: How to change main menu screen according to system time?
Last edited by Imperf3kt on Wed Aug 24, 2022 10:06 am, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: How to change main menu screen according to system time?
Isn't this screen redrawn like other screens? Like when you go to some game_menu screen and back to the main_menu? I mean it's not like this is supposed to change when the player sits hours inside the menu, right?
The time is checked every time the screen is drawn, not just at the start of the game.
edit: You could let it check in "realtime" including a timer that loops and checks after every minute if you want to.
-
Alvsvartr
- Newbie
- Posts: 20
- Joined: Wed Aug 17, 2016 9:31 am
- Soundcloud: nebelwand-ua
- Location: Ukraine
- Contact:
Re: How to change main menu screen according to system time?
Oh, I see! I was a bit tired at the moment and added just a transparent image here =)) I've used manual selection to find the command "add". It was something! Thank you!m_from_space wrote: ↑Mon Aug 22, 2022 1:52 amCode: Select all
define gui.main_menu_background = None
And I'd like to add one more variant to make things going:
At first, let's go to the gui.rpy:
Code: Select all
init python:
import datetime
define gui.main_menu_background = ["images/start1.png", "images/start2.png", "images/start3.png", "images/start4.png"]Code: Select all
screen main_menu():
## This ensures that any other menu screen is replaced.
tag menu
style_prefix "main_menu"
# <<<
#add gui.main_menu_background
$ ct = datetime.datetime.now().hour
if 6 <= ct < 11:
add gui.main_menu_background[0]
elif 11 <= ct < 18:
add gui.main_menu_background[1]
elif 18 <= ct < 21:
add gui.main_menu_background[2]
else:
add gui.main_menu_background[3]
# >>>
## This empty frame darkens the main menu.
frame:
[...]Moreover, there's one more alternative:
Code: Select all
init python:
import datetime
define gui.main_menu_background = ConditionSwitch("datetime.datetime.now().hour >= 21", "gui/main_menu_night.png",
"datetime.datetime.now().hour >= 18", "gui/main_menu_evening.png",
"datetime.datetime.now().hour >= 11", "gui/main_menu_afternoon.png",
"datetime.datetime.now().hour >= 6", "gui/main_menu_morning.png",
"True", "gui/main_menu_night.png")So, we have at least three alternatives, yet we can choose all of them.
-
Alvsvartr
- Newbie
- Posts: 20
- Joined: Wed Aug 17, 2016 9:31 am
- Soundcloud: nebelwand-ua
- Location: Ukraine
- Contact:
Re: How to change main menu screen according to system time?
I checked it, and the solution provided by anne O'nymous changes the image in real-time.
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: How to change main menu screen according to system time?
Well, it's basically the same solution as I proposed, I just didn't know that you can get the hours out of datetime this easily. My solution doesn't need a list on the other hand, I don't get why this was even suggested. You just don't need a config variable that is there for making changes more easy.
The ConditionSwitch is neat, but on the other hand calls datetime.now() multiple times, so it's not the most efficient (not that it really matters).
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]