Ren'Py [SOLVED]Calendar System

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,917
I'm trying to set a really simple calendar system that would only display the day of the week and the current hour. The plan is just for it to be displayed, since it's kind of relevant to the context of the game, and also to use it to display variants of the backgrounds.

Python:
init python:
    class calendar(object):
        def __init__(self):
            self.day = 1
            self.hour = 1
            self.weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
            self.time_of_day = ["8:00 A.M.", "12:00 P.M.", "4:00 P.M.", "8:00 P.M.", "12:00 A.M."]

        @property
        def weekday(self):
            return self.weekdays[(self.day-1)%7]

        @property
        def time(self):
            return self.time_of_day[(self.hour-1)%5]

        def advance_weekday(self):
            self.day += 1

        def advance_time(self):
            self.hour += 1

default clock = calendar()

screen clock_marker:
    add "time_display.png" xalign 0.0 yalign 0.0
    vbox:
        xalign 0.0
        yalign 0.0
        spacing 5
        textbutton "{b}[clock.weekday]{/b}"
        textbutton "{b}[clock.time]{/b}"
This indeed displays the time correctly, and I can advance time with the specific commands, but I have a few problems with this.
  1. If I want it to go forward, I have to input "$ clock.advance_time()" a couple of times. I tried "$ clock.advance_time(2)" so the value doubles, but doesn't work that way, it seems.
  2. Additionally, I would rather set an specific hour rather than just advance it, since, again, is relevant to the plot.
  3. I'm not exactly sure how to make the background variants display.
  4. I also want to round time in a new property that would be morning, noon and night.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,171
Python:
init python:
    [...]
        @property
        def weekday(self):
            return self.weekdays[(self.day-1)%7]

        @property
        def time(self):
            return self.time_of_day[(self.hour-1)%5]

        def advance_weekday(self):
            self.day += 1

        def advance_time(self):
            self.hour += 1
[...]
I have a big problem regarding this code. It just stack the hours and the days, but they aren't linked together. Call "advance_time" 100 time, and you'll still be on the exact same day than before. It should have been wrote like this :
Code:
        def advance_time(self, step=1):
            self.hour += step
            while self.hour >= len( self.time_of_day ):
                self.advance_weekday()
                self.hour = self.hour % len( self.time_of_day )
And now you can advance the time for one period $ clock.advance_time() or more than one period $ clock.advance_time( 4 ).


  • Additionally, I would rather set an specific hour rather than just advance it, since, again, is relevant to the plot.
You need to know the hour you want to go to $ clock.hour = 3
Note: An array index start at 0, so the "3" here mean "8:00 PM"


  • I'm not exactly sure how to make the background variants display.
One of the many way is to define an array with the background you want for each period of the day, then display it according to the actual period :
Code:
define variantBackground = [ "0800AM_background.png", 
                             "1200PM_background.png",
                             "0400PM_background.png",
                             "0800PM_background.png",
                             "1200AM_background.png" ]
[...]
screen clock_marker:
    add variantBackground[clock.hour] xalign 0.0 yalign 0.0
    [...]

  • I also want to round time in a new propert
  • y that would be morning, noon and night.
Just change this line :
self.time_of_day = ["8:00 A.M.", "12:00 P.M.", "4:00 P.M.", "8:00 P.M.", "12:00 A.M."]
to :
self.time_of_day = ["Morning", "Noon", "Night"]
And also change the line for the background according to it.


In the end, the code looks like this :
Python:
    class Calendar(object):

        def __init__(self):
            self.DoW = 0
            self.hour = 0
            self.weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
            self.time_of_day = ["Morning", "Noon", "Night"]
            self.background_image = [ "morning_background.png", "noon_background.png", "night_background.png" ]

        @property
        def background( self ):
            return self.background_image[self.hour]

        @property
        def weekday(self):
            return self.weekdays[self.DoW % 7]

        @property
        def time(self):
            return self.time_of_day[self.hour]

        def advance_weekday(self, step=1):
            self.DoW += step

        def advance_time(self, step=1):
            self.hour += step
            while self.hour >= len( self.time_of_day ):
                self.advance_weekday()
                self.hour = self.hour % len( self.time_of_day )

default clock = Calendar()

screen clock_marker:
    add clock.background xalign 0.0 yalign 0.0
    vbox:
        xalign 0.0
        yalign 0.0
        spacing 5
        textbutton "{b}[clock.weekday]{/b}"
        textbutton "{b}[clock.time]{/b}"
 
Last edited:
  • Like
Reactions: AmazonessKing

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,917
Great post, thanks! But

I have a big problem regarding this code. It just stack the hours and the days, but they aren't linked together. Call "advance_time" 100 time, and you'll still be on the exact same day than before. It should have been wrote like this :
Code:
        def advance_time(self, step=1):
            self.hour += step
            while self.hour >= len( self.time_of_day ):
                self.advance_weekday()
                self.hour = self.hour % len( self.time_of_day )
And now you can advance the time for one period $ clock.advance_time() or more than one period $ clock.advance_time( 4 ).
I actually did that on purpose. I don't want hours to advance the day, again for plot related reasons. I want to set the day individually, unrelated to time.
Just change this line :
self.time_of_day = ["8:00 A.M.", "12:00 P.M.", "4:00 P.M.", "8:00 P.M.", "12:00 A.M."]
to :
self.time_of_day = ["Morning", "Noon", "Night"]
And also change the line for the background according to it.
I need BOTH. And I want the morning/noon/night to work according to the time of the the day, which will be "8:00 A.M." and "12:00 P.M." to morning, to "4:00 P.M." to noon and so on. This is because the backgrounds only have 3 variants, but I need specific hours for plot related reasons. So I want that whenever I change the hour, the morning/noon/night cycle changes along the hour. I tried this yesterday
Python:
init python:
    class calendar(object):
        def __init__(self):
            self.day = 1
            self.hour = 1
            self.weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday"] # arrange these so first weekday goes first
            self.hour_of_day = ["8:00 A.M.", "12:00 P.M.", "4:00 P.M.", "8:00 P.M.", "12:00 A.M."] # add or remove to increase time of day slots
            self.time_of_day = ["Morning", "Noon", "Night"]

        @property
        def weekday(self):
            return self.weekdays[(self.day-1)%5]

        @property
        def hour(self):
            return self.hour_of_day[(self.hour-1)%5]

        @property
        def time(self):
            return self.time_of_day[(self.hour-1)(self.hour-3)(self.hour-4,5)%3]
I changed time to hours, to reflect the actual hours and time to time of the day. It evidently didn't work since the time don't pick up the hours, which is the one thing I want linked and automatic, but I will try your code and toy around with it a little.


Also! Additional question. How do I modify the font of this class alone?
 

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,917
I manage to automatize the morning/noon/night cycle to go according to the hour. So if I set the clock to 8 A.M. it will display morning, if I set it to 8 P.M. it will display night and if I set it to 4 P.M. it will display noon.
Python:
init python:
    class Calendar(object):

            def __init__(self):
                self.day = 0
                self.hourclock = 0
                self.weekdays = ["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]
                self.hour_of_day = ["8:00 A.M.", "12:00 P.M.", "4:00 P.M.", "8:00 P.M.", "12:00 A.M."]
                self.time_of_day = ["MORNING", "NOON", "NIGHT"]

            @property
            def weekday(self):
                return self.weekdays[self.day]

            @property
            def hour(self):
                return self.hour_of_day[self.hourclock]

            @property
            def time(self):
                if (self.hourclock<=1):
                    return self.time_of_day[0]
                elif (self.hourclock==2):
                    return self.time_of_day[1]
                elif (self.hourclock>=1):
                    return self.time_of_day[2]

            def advance_weekday(self, step=1):
                self.day += step

            def advance_hour(self, step=1):
                self.hourclock += step

default clock = Calendar()

screen clock_marker:
    add "time_display.png" xalign 0.0 yalign 0.0
    vbox:
        xalign 0.0
        yalign 0.0
        spacing 5
        textbutton "{b}[clock.weekday]{/b}"
        textbutton "{b}[clock.time]{/b}"
        textbutton "{b}[clock.hour]{/b}"
I still need to change the font, though.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,171
I still need to change the font, though.

Code:
screen clock_marker:
    add "time_display.png" xalign 0.0 yalign 0.0
    vbox:
        xalign 0.0
        yalign 0.0
        spacing 5
        # either this
        textbutton "{font=myfont.ttf}{b}[clock.weekday]{/b}{/font}"
        # or that
        textbutton "{b}[clock.time]{/b}" style "altFont"

style altFont is default:
    font "myfont.ttf"
 
  • Like
Reactions: AmazonessKing

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,917
Code:
screen clock_marker:
    add "time_display.png" xalign 0.0 yalign 0.0
    vbox:
        xalign 0.0
        yalign 0.0
        spacing 5
        # either this
        textbutton "{font=myfont.ttf}{b}[clock.weekday]{/b}{/font}"
        # or that
        textbutton "{b}[clock.time]{/b}" style "altFont"

style altFont is default:
    font "myfont.ttf"
Thanks a lot. Now my code is up and running, but I still have a problem with the variant backgrounds, I have something like this.

Python:
define bg_tropical_island = "morning_bg tropical island.png", "noon_bg tropical island.png", "night_bg tropical island.png"

label start:

scene bg_tropical_island with fade
Obviously with the previous python code but the scene bg_tropical_island reads "bg_tropical_island" as an standalone background without any image stored, because, well, there's no image called that.
You don't have permission to view the spoiler content. Log in or register now.
What I was trying to do was something like you do with characters, like this.
Python:
define e = Character("Eileen", image="Eileen")

image Eileen Happy = "images/Character Portraits/Eileen Happy.png"
image Eileen Neutral = "images/Character Portraits/Eileen Neutral.png"
So obviously it's easier to handle the character with multiple images, and I was wondering if I can do something similar based on the previous calendar system, but for backgrounds and using the scene command.
 

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,917
So I ended with a code like this
Python:
image Tropical_Island Morning = "images/Backgrounds/bg tropical_island morning.png"
image Tropical_Island Noon = "images/Backgrounds/bg tropical_island noon.png"
image Tropical_Island Night = "images/Backgrounds/bg tropical_island night.png"
define Tropical_Island = Background("Tropical Island", image="Tropical_Island")
Problem is that "Background" object is not defined so I'm looking into creating a object myself:
And I feel like I getting deep into something a beginner will spend days trying to figure out, so I might as well ask for help already.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,655
23,746

Python:
image bg tropical_island = ConditionSwitch(
    "clock.time == 'Morning'", "images/Backgrounds/bg tropical_island morning.png",
    "clock.time == 'Noon'", "images/Backgrounds/bg tropical_island noon.png",
    "True", "images/Backgrounds/bg tropical_island night.png")
 
  • Like
Reactions: AmazonessKing