OS Calendar in Ren'py
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.
OS Calendar in Ren'py
I know that I can create my own calendar but can I as well ask Ren'py to check my operating system / bios calendar, date?
fe.
if sysdata = 1 April:
fe.
if sysdata = 1 April:
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- netravelr
- Miko-Class Veteran
- Posts: 504
- Joined: Thu Jan 28, 2010 2:31 am
- Completed: Culina: Hands in the Kitchen, Culina: The Spirit of Cooking, Saving Zoey
- Projects: Love at the Laundromat
- Organization: Lakeview Interactive
- Deviantart: netravelr
- Location: USA
- Contact:
Re: OS Calendar in Ren'py
Hopefully this'll be some help: https://docs.python.org/2/library/calendar.html
Technical Designer/Programmer
Game Design Portfolio - Project updates on my Twitter
Experienced in: C/C++/C#, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."
Re: OS Calendar in Ren'py
To do this I think that I need calendar code that is here:
https://hg.python.org/cpython/file/2.7/Lib/calendar.py
If so then how can I import python (.py) code into renpy?
https://hg.python.org/cpython/file/2.7/Lib/calendar.py
If so then how can I import python (.py) code into renpy?
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: OS Calendar in Ren'py
You should be able to just do:
Code: Select all
init python:
import calendar
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: OS Calendar in Ren'py
Thank you for answer. After importing, calendar date still doesn't seem to be defined. I hoped that it will be complete code but it seems that it isn't or I'm missing something. Can anyone who might be familiar with this code tell me if I'm going in good direction at all?
I wanted to test if I can run anything after checking in this example month of the year:
Calendar code link as above: https://hg.python.org/cpython/file/2.7/Lib/calendar.py
This code is over 700 lines long and is above my understanding of how python works.
Here is documentation of this code as well: https://docs.python.org/2/library/calendar.html
I wanted to test if I can run anything after checking in this example month of the year:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 35, in script
if month_name == 3:
File "game/script.rpy", line 35, in <module>
if month_name == 3:
NameError: name 'month_name' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 35, in script
if month_name == 3:
File "D:\Downloads\renpy-6.18.3-sdk\renpy\ast.py", line 1587, in execute
if renpy.python.py_eval(condition):
File "D:\Downloads\renpy-6.18.3-sdk\renpy\python.py", line 1416, in py_eval
return eval(py_compile(source, 'eval'), globals, locals)
File "game/script.rpy", line 35, in <module>
if month_name == 3:
NameError: name 'month_name' is not defined
Windows-post2008Server-6.2.9200
Ren'Py 6.18.3.761
This code is over 700 lines long and is above my understanding of how python works.
Here is documentation of this code as well: https://docs.python.org/2/library/calendar.html
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: OS Calendar in Ren'py
The problem is almost certainly in your code, rather than the python code.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: OS Calendar in Ren'py
Thank you for answer and checking the code out.
I just made quick code in Ren'py to check if calendar is defined and I still encounter same error. Here it is:
Same error:
I just made quick code in Ren'py to check if calendar is defined and I still encounter same error. Here it is:
Code: Select all
init python:
import calendar
image bgwhite = "#fff"
image bgblack = "#000"
define e = Character (("Ema"), color="#FF9966")
define rubwin = Character(("Im window"), color="#FF9966", window_top_margin=200, window_left_margin=200, window_right_margin=200, window_bottom_margin=200)
label start:
e "whatever"
if month_name == 3:
scene bgwhite
e "..."
e "Lorem Ipsum."
jump start
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 14, in script
if month_name == 3:
File "game/script.rpy", line 14, in <module>
if month_name == 3:
NameError: name 'month_name' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 14, in script
if month_name == 3:
File "D:\Downloads\renpy-6.18.3-sdk\renpy\ast.py", line 1587, in execute
if renpy.python.py_eval(condition):
File "D:\Downloads\renpy-6.18.3-sdk\renpy\python.py", line 1416, in py_eval
return eval(py_compile(source, 'eval'), globals, locals)
File "game/script.rpy", line 14, in <module>
if month_name == 3:
NameError: name 'month_name' is not defined
Windows-post2008Server-6.2.9200
Ren'Py 6.18.3.761
Playground 0.0
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
Re: OS Calendar in Ren'py
Ok I checked calendar.py code again and I saw that in lines 8, 9, 10, 621 it wants to import following libraries.
I downloaded 2.7.9 version of python from https://www.python.org/downloads/ installed it and I searched for libraries mentioned above.
I found:
locale.py (97 kb)
datetime.h (8.11 kb problem here is that .h is c++ library)
couldn't find sys.py in installed folder
optparse.py (59.7 kb)
any help suggestions or where I can find libraries probably required for calendar.py?
Code: Select all
import sys
import datetime
import locale as _locale
import optparse
I found:
locale.py (97 kb)
datetime.h (8.11 kb problem here is that .h is c++ library)
couldn't find sys.py in installed folder
optparse.py (59.7 kb)
any help suggestions or where I can find libraries probably required for calendar.py?
Last edited by Luxliev on Fri Mar 06, 2015 12:05 pm, edited 1 time in total.
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: OS Calendar in Ren'py
Okay - what are you actually trying to do?
Simply importing the calendar module won't do anything other than importing the calendar module - it won't set the month_name variable for you. You probably don't want the calendar module - time.localtime() might be your best bet - but I need to know what you're actually trying to do to be able to advise you correctly.
Simply importing the calendar module won't do anything other than importing the calendar module - it won't set the month_name variable for you. You probably don't want the calendar module - time.localtime() might be your best bet - but I need to know what you're actually trying to do to be able to advise you correctly.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: OS Calendar in Ren'py
I want to implement system date that will be checked whenever I start game so I could add events that would start/activate on specific real date. Best example April Fools or calendar man from batman game.
Code: Select all
if month_day == 4 and day_name == 1:
jump aprilfoolscode
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: OS Calendar in Ren'py
I think the datetime module is what you want here.
Code: Select all
init python:
import datetime
today = datetime.date.today()
Code: Select all
if today.month == 4 and today.day == 1:
jump aprilfoolscode
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: OS Calendar in Ren'py
Thank you it works as intended
I had to install 3.4.3 version of python from https://www.python.org/downloads/ to get datetime.py library for some reason there is only c++ datetime lib (.h instead of .py) in 2.7.9 version
For everyone else here is code example (you need to install Python 3.4.3 and copy from install folder to your game folder datetime.py :
One question though: What happens if game is saved and then reloaded in this example? Does date variable is written and saved from first day game was saved or will it be updated?
Example:
I started my game on 30 march and saved my game.
Next day I loaded game and date is 1 April (day when event should began). What will happen.
What today.month today.day variable number will be? When I start game and data is read from script.rpy today.month and today.day will be saved only once during init phase right? Or am I wrong?
Can I implement this code to some menu.rpy file if there is any so today.month and today.day will be always same as the date I run my game? Or maybe I can use code today = datetime.date.today() outside of init: ?
I hope that you understand what I have in mind.
I had to install 3.4.3 version of python from https://www.python.org/downloads/ to get datetime.py library for some reason there is only c++ datetime lib (.h instead of .py) in 2.7.9 version
For everyone else here is code example (you need to install Python 3.4.3 and copy from install folder to your game folder datetime.py :
Code: Select all
init python:
import datetime
today = datetime.date.today()
image bgwhite = "#fff"
image bgblack = "#000"
define e = Character (("Ema"), color="#FF9966")
define rubwin = Character(("Im window"), color="#FF9966", window_top_margin=200, window_left_margin=200, window_right_margin=200, window_bottom_margin=200)
label start:
e "whatever"
##current date
if today.month == 3 and today.day == 6:
scene bgwhite
e "..."
jump start
e "Lorem Ipsum."
jump start
Example:
I started my game on 30 march and saved my game.
Next day I loaded game and date is 1 April (day when event should began). What will happen.
What today.month today.day variable number will be? When I start game and data is read from script.rpy today.month and today.day will be saved only once during init phase right? Or am I wrong?
Can I implement this code to some menu.rpy file if there is any so today.month and today.day will be always same as the date I run my game? Or maybe I can use code today = datetime.date.today() outside of init: ?
I hope that you understand what I have in mind.
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: OS Calendar in Ren'py
Luxliev wrote: I had to install 3.4.3 version of python from https://www.python.org/downloads/ to get datetime.py library for some reason there is only c++ datetime lib (.h instead of .py) in 2.7.9 version
It will be updated when Ren'Py starts. So if the game is started on March 31 at 2359, the date will remain March 31, even if the clock ticks forwards to April 1.One question though: What happens if game is saved and then reloaded in this example? Does date variable is written and saved from first day game was saved or will it be updated?
However, if the player saves, exits Ren'Py, starts Ren'Py back up, and loads, the date will be correct.
It's probably best to just call datetime.date.today() right before checking it, using code like:
Code: Select all
init python:
import datetime
Code: Select all
$ today = datetime.date.today()
if (today.month == 4) and (today.date == 1):
# ...
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: OS Calendar in Ren'py
Thanks for all your time explaining everything to me. I saved game yesterday and checked it today. Everything worked as it should. I also found out that I don't have to copy datetime.py lib from python installer it was already integrated in Ren'py which is nice.
Problem solved. Thanks again... I'll be back
Problem solved. Thanks again... I'll be back
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc
Forum with my music: http://luxliev.proboards.com/
Forum with my music: http://luxliev.proboards.com/
Who is online
Users browsing this forum: No registered users