[solved]Detecting real-world date and time for use in-game
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.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
[solved]Detecting real-world date and time for use in-game
I don't seem to be turning up anything by googling and my Python knowledge is minimal.
So I was wondering if this is possible?
In the most basic sense, I want to add a different main menu background if the date matches a certain day.
A usage example would be I want to give my game a christmas theme if the day == December 24-27
This may include character sprites or just menu imagebuttons (possibly a parralax effect, etc)
Or on April 1st, my game flips upside down.
Is there any way to get the real world date into a variable of some sort from which I can use to create these events?
E: hmm, google turns up the 'datetime' function. Could this be used?
https://docs.python.org/2/library/datetime.html
So I was wondering if this is possible?
In the most basic sense, I want to add a different main menu background if the date matches a certain day.
A usage example would be I want to give my game a christmas theme if the day == December 24-27
This may include character sprites or just menu imagebuttons (possibly a parralax effect, etc)
Or on April 1st, my game flips upside down.
Is there any way to get the real world date into a variable of some sort from which I can use to create these events?
E: hmm, google turns up the 'datetime' function. Could this be used?
https://docs.python.org/2/library/datetime.html
Last edited by Imperf3kt on Mon Nov 27, 2017 4:49 pm, 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
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Detecting real-world date and time for use in-game
If you look at the Clock recipe in my signature and do a search for "datetime" you can see an example of importing and using date time...the clock uses it for time, not date, but it might give you an idea.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
- Donmai
- Eileen-Class Veteran
- Posts: 1958
- Joined: Sun Jun 10, 2012 1:45 am
- Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
- Projects: Slumberland
- Location: Brazil
- Contact:
Re: Detecting real-world date and time for use in-game
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)
TOIRE NO HANAKO (A Story About Fear)
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Detecting real-world date and time for use in-game
Thanks Trooper6, I had looked at your clock code previously but it was too hard for me to understand how I could manipulate it how I wanted. (Or rather, there was so much code that I gave up before I started)
Now lets see, there's halloween, easter, christmas, new years eve/day, april 1st... Any other significant dates I should include? International, of course, so no 4th of July. Unless there's also a way to detect system region?
Truly awesome! As always this community is really helpful, thanks!
Now lets see, there's halloween, easter, christmas, new years eve/day, april 1st... Any other significant dates I should include? International, of course, so no 4th of July. Unless there's also a way to detect system region?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Miko-Class Veteran
- Posts: 758
- Joined: Tue Jun 22, 2010 12:54 am
- Completed: Christmas
- IRC Nick: DragoonHP
- Location: Zion Island, Solario
- Contact:
Re: [solved]Detecting real-world date and time for use in-game
Well you can detect the timezone.
Code: Select all
# If you use the code Donmai linked to, you don't need to import time here
import time
current_tz = time.tzname
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: [solved]Detecting real-world date and time for use in-game
Sorry to drag this up again, but I finally got around to giving this a go tonight.
At first, I got it to work great, but after some more editing of my game, I now cannot get it to NOT show a Christmas theme.
Here is my main menu in it's entirety
I have not edited options.rpy and the only thing I added to gui.rpy was
Which I placed at line 90.
If I remove
Then the original background and music are used, but obviously thats not very useful.
I've tried various things, even changing datetime from an init and using $, to init python.
At first, I got it to work great, but after some more editing of my game, I now cannot get it to NOT show a Christmas theme.
Here is my main menu in it's entirety
Code: Select all
## Main Menu screen ############################################################
screen main_menu():
tag menu
style_prefix "main_menu"
if month == 12 and day == 24 or 25 or 26 or 27:
$ m_music = "music/We Wish You.mp3"
add gui.xmas_main_menu_background
else:
add gui.main_menu_background
on "show" action Play("music", m_music)
frame:
pass
use navigation
if gui.show_name:
vbox:
text "[config.name!t]":
style "main_menu_title"
text "[config.version]":
style "main_menu_version"
style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text
style main_menu_frame:
xsize 280
yfill True
background "gui/overlay/main_menu.png"
style main_menu_vbox:
xalign 1.0
xoffset -20
xmaximum 800
yalign 1.0
yoffset -20
style main_menu_text:
properties gui.text_properties("main_menu", accent=True)
style main_menu_title:
properties gui.text_properties("title")
style main_menu_version:
properties gui.text_properties("version")
init python:
import time
year, month, day, hour, minute, second, dow, doy, dst = time.localtime()
Code: Select all
define gui.xmas_main_menu_background = "gui/xmas_main_menu.png"
If I remove
Code: Select all
if month == 12 and day == 24 or 25 or 26 or 27:
$ m_music = "music/We Wish You.mp3"
add gui.xmas_main_menu_background
else:
I've tried various things, even changing datetime from an init and using $, to init python.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: [solved]Detecting real-world date and time for use in-game
and day in [24,25,26,27]:
using or does not work like it works in speech, your 'or 25' basically just says 'or 25 == True' ...
using or does not work like it works in speech, your 'or 25' basically just says 'or 25 == True' ...
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3785
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: [solved]Detecting real-world date and time for use in-game
Thank you.
I guess I better go study Python lists.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: [solved]Detecting real-world date and time for use in-game
The code Remix gave is the best way to do it.
The long way of doing what you wanted to so...which I hope illustrates what you did wrong...would be:
but
is much better!
The long way of doing what you wanted to so...which I hope illustrates what you did wrong...would be:
Code: Select all
if month == 12 and (day == 24 or day == 25 or day ==26 or day == 27):
Code: Select all
if month == 12 and day in [24, 25, 26,27]:
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Who is online
Users browsing this forum: Google [Bot]