[solved]what is the best way to make a Calendar run in the background?

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
User avatar
ninjew_42
Newbie
Posts: 4
Joined: Fri Jul 13, 2018 10:01 pm
Tumblr: glompme
Contact:

[solved]what is the best way to make a Calendar run in the background?

#1 Post by ninjew_42 »

I need it to run in the background so I don't need to jump to update the date, month, and year and weekday and hope that I end up jumping back to where I left off.
The player needs to be able to stay up all night if they want to with sleep being an optional trigger for updating the date. Right now I'm using the code below at the end of day and trying it in screens.rpy works for exactly 1 day then it's suddenly August 33rd. Ideally I'd like to do the same for the weekday as well but my brain is fried on this one.

Any help would be amazing.


Variables used:

Code: Select all

default month = "August"
default current_year = 2022
default current_date = 1
default current_weekday = "Monday"
default leap_year = False
default hour = 6
default minute = 0
default minute_alt = "00"
default ampm = "am"
default current_time = "Early Morning"
Weekday Code:

Code: Select all

    $ current_date +=1
    if current_weekday == "Monday":
        $ current_weekday = "Tuesday"
    elif current_weekday == "Tuesday":
        $ current_weekday = "Wednesday"
    elif current_weekday == "Wednesday":
        $ current_weekday = "Thursday"
    elif current_weekday == "Thursday":
        $ current_weekday = "Friday"
    elif current_weekday == "Friday":
        $ player_cash +=0
        $ current_weekday = "Saturday"
    elif current_weekday == "Saturday":
        $ current_weekday = "Sunday"
    else:
        $ current_weekday = "Monday"
    jump end_of_day
Calendar Code (currently in my label end_of_day):

Code: Select all

    if month == "December":
        if current_date == 32:
            $ month = "January"
            $ current_date = 1
            $ current_year += 1
            if current_year == 2024:
                $ leap_year = True
            if current_year == 2028:
                $ leap_year = True
            else:
                $ leap_year = False
    elif month == "November":
        if current_date == 31:
            $ month = "December"
            $ current_date = 1
    elif month == "October":
        if current_date == 32:
            $ month = "November"
            $ current_date = 1
    elif month == "September":
        if current_date == 31:
            $ month = "October"
            $ current_date = 1
    elif month == "August":
        if current_date == 32:
            $ month = "September"
            $ current_date = 1
    elif month == "July":
        if current_date == 32:
            $ month = "August"
            $ current_date = 1
    elif month == "June":
        if current_date == 31:
            $ month = "July"
            $ current_date = 1
    elif month == "May":
        if current_date == 32:
            $ month = "June"
            $ current_date = 1
    elif month == "April":
        if current_date == 31:
            $ month = "May"
            $ current_date = 1
    elif month == "March":
        if current_date == 32:
            $ month = "April"
            $ current_date = 1
    elif month == "Febuary":
        if leap_year:
            if current_date == 30:
                $ month = "March"
                $ current_date = 1
        else:
            if current_date == 29:
                $ month = "March"
                $ current_date = 1
    else:
        if current_date == 32:
            $ month = "Febuary"
            $ current_date = 1
Last edited by ninjew_42 on Sat Jul 21, 2018 11:19 am, edited 1 time in total.
Most people in my experience wouldn't know reason if it walked up and shook their hand. You can count Gul Dukat among them.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: what is the best way to make a Calendar run in the background?

#2 Post by trooper6 »

How does time advance in your game?
Does time advance by an hour for every turn? How to you advance a turn? Or do you want this to go in real time?
Or can the players do as much as they want until they click a "Next Day" button?
If it is Monday and they chose not to sleep...does it just stay Monday?
What do you mean by "run in the background?"
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

User avatar
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: what is the best way to make a Calendar run in the background?

#3 Post by Remix »

I semi hate to say this (seeing how much work you have obviously done already) ... It might be best to try Python datetime objects through Ren'Py output translation...

Code: Select all

init python:

    import datetime

    class GameTime(object):

        def __init__(self, dt="Jan 01 2018"):
            self._dt = datetime.datetime.strptime( dt, "%d %b %Y" )

        @property
        def dt(self):
            return _strftime("%d %b %Y %H:%M", self._dt.timetuple())

        def alter(self, **kwargs):
            self._dt += datetime.timedelta( **kwargs )


default gt = GameTime("01 Aug 2022")

label start:

    "[gt.dt]"
    $ gt.alter( days=1, hours=22, minutes=30 )
    "[gt.dt]"
    $ gt.alter( days=41 )
    "[gt.dt]"
    $ gt.alter( hours = -29 )
    "Spooky time travel backwards ... [gt.dt]"
Hopefully enough there to get you started... *cough* umm started in another direction...
Frameworks & Scriptlets:

User avatar
ninjew_42
Newbie
Posts: 4
Joined: Fri Jul 13, 2018 10:01 pm
Tumblr: glompme
Contact:

Re: what is the best way to make a Calendar run in the background?

#4 Post by ninjew_42 »

I'm not quite to the advancing of time yet but essentially the player clicks a button (like go outside to a store 30 minutes away) and the button will increase the minutes which in turn will increase hours, then days, then months, and years. I was trying to get the big stuff running first.
Different Actions or movement to different areas increase minutes and/or hours by different amounts.
When it hits midnight it should immediately switch over from Monday to Tuesday and so on for each new day.

I think I found a way to get it to work without any problems by having a label call that returns at the end back to where it was called from using the information from this-
https://www.renpy.org/doc/html/label.html

It is working thus far.
Most people in my experience wouldn't know reason if it walked up and shook their hand. You can count Gul Dukat among them.

Post Reply

Who is online

Users browsing this forum: Sugar_and_rice