Need help with a simple hour and day system for Renpy

ronhowardeen

Newbie
Dec 22, 2018
49
80
I've already unren'd several games including the often recommended Lab Rats and I still can't figure out how to do a simple hour system and a simple day system. The game is a sandbox type game like Big Brother. The amount of time in a day would be from 8 am to 10 pm(8 to 22), so 15 total hours. Each event would add one hour. At 11 pm(23), the time would loop back to 8 am and put a counter on the day, which would just be used to determine what day of the week it is. Sounds really simple but I can't find any code to modify that works.
 

ronhowardeen

Newbie
Dec 22, 2018
49
80
I should have mentioned I already searched here and the lemma soft forums. I couldn't find anything on what I mentioned. I ended up just restructuring my game to kick back to the same script after every event and check for hours. Thanks anyway.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,774
untested:
Python:
label endOfTheDay:
    "Let's call it a day and go to bed"
    call dayTime

label dayTime:
    $ daylyActions -= 1
    if daylyActions <= 0:
        $ daylyActions = 15
        $ currentDay += 1
        scene black with fade
        $renpy.notify("Day " + str(currentDay))
        window hide
        pause 2
        jump MCRoomMorning
    else:
        return
    
label MCRoomMorning:
    "You wake up in the morning"
You'll have to call dayTime after every scene that uses action points/hours.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,199
I should have mentioned I already searched here and the lemma soft forums.
I don't remember where it's located, but I already wrote at least one of them, perhaps two, here. As for the official forum, there's few of them. So, either you haven't searched enough, or you haven't said enough regarding what you're effectively searching.


Keeping recreation draft :
[Note: it's 3AM here and I wrote it on the fly. But normally it works]
Python:
# Keep track of the actual hour ; the game will start at 8 AM.
default hour = 8
# Keep track of the actual day ; the game will obviously start at day 1.
default day = 1
# Keep track of the Day of the Week ; the game start a Sunday.
default DoW = 0
# Transform DoW into a string
define sDoW = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]

label advanceTime( step=1 ):
    # Increment the hour
    $ hour += step
    # If the day isn't finished, just return
    if hour < 24 :
        return
    # Else start a new day cycle.
    $ hour %= 24
    # And obviously advance the day, but don't touch to the hour.
    jump advanceDay( False )

label advanceDay( reset=True ):
    # Increment the day.
    $ day += 1
    # Increment the day of the week.
    $ DoW += 1
    # It's a 7 day cycle, after Saturday (6) come Sunday (0).
    if DoW = 7:
        $ DoW = 0
    # The day changed because the MC slept.
    # It awake at 6AM
    if reset is True:
        $ hour = 6
    return

label whatever:
    "You do this"
    "You do that"
    "It took you one hour"
    # Increment the time.
    call advanceTime
    "What do you want to do now"
    menu:
       [...]

label sleeping:
    "You go to your bedroom and decide to sleep"
    # Increment the day.
    call advanceDay
    "You're fresh, do you want to take a breakfast ?"
    [...]

label works:
    "You decide to works for four hours."
    # Increment the time by 4 units/hours
    call advanceTime( 4 )
    "Oh, it's time to lunch"
    [...]

screen HUD():
    vbox:
        text "We are %s" % sDoW[DoW]
        text "It's the day [day]"
        text "It's [hour]"
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,808
24,388
here is another absolute minimalistic approach.
Python:
init python:
    class Time(object):
        def __init__(self, begin=0, end=24, hourlength=60, weeklength=7):
            self._begin = begin * hourlength
            self._hours = end - begin
            self._hourlength = hourlength
            self._weeklength = weeklength
            self._minutes = 0
            self._daynames = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

        @property
        def minute(self):
            return self._minutes % self._hourlength

        @property
        def hour(self):
            return self._minutes / self._hourlength % self._hours + self._begin

        @property
        def day(self):
            return self._minutes / self._hourlength / self._hours + 1

        @property
        def wkday(self):
            return self._daynames[self._minutes / self._hourlength / self._hours % self._weeklength]
        
        @minute.setter
        def minute(self, minutes=0):
            self._minutes += minutes
            if self._minutes < 0:
                self._minutes = 0
        
        @hour.setter
        def hour(self, hours=0):
            self.minute = hours * self._hourlength

        @day.setter
        def day(self, days=0):
            self.hour = days * self._hours
in your script declare your time object and use the getter and setter accordingly.
Python:
label start:

    $ t = Time(your start hour, your end hour, minutes per hour, days per week) # incase your game plays on another planet with a different time schedule ;)

    $ t.minute = 30 # to advance 30 minutes
    $ t.minute = -15 # to go back 15 minutes
    $ t.hour = 2
    $ t.hour = -1
    $ t.day = 7
    $ t.day = -1
    
    $ currHour = t.hour
    $ currMinutes = t.minute
    $ curDay = t.day
    $ currWkDay = t.wkday
i'm back later for questions. right now i've fallen asleep.