Ren'Py Time system

Georges.0843

New Member
Oct 4, 2022
5
0
How can I create a time system that displays the 24 hours in PM/ AM as well as the days of the week and months?
 
Sep 26, 2021
232
266
Essentially you would need variables for every data point that you want to display. Something like:

month = "January"
day = 1
year = 1970
amPM = "AM"
hour = 12
minute = 1

Then you would need to instruction your UI to display the values of all of those variables. Then later on when the time or date changes in your story you just change the values of your variables in the game script.
 
  • Like
Reactions: Georges.0843

MidnightArrow

Active Member
Aug 22, 2021
500
451
Real-life time? You need to fetch that from the operating system through the OS module.

If you mean fake in-game time, you need to store them as variables, display them with a custom screen, and use functions to convert them to however you want to show them. Since Python is a fucking awful, shitty, garbage-tier programming language, it doesn't have enums (or type safety at all) or switch statements, so you have to do the legwork yourself.

Code:
MONDAY = 1
TUESDAY = 2
...
SUNDAY = 7

current_weekday = MONDAY

def get_weekday_name(weekday):
    if weekday == MONDAY:
        return "Monday"
    elif weekday == TUESDAY:
        return "Tuesday"

def increment_weekday(weekday):
    weekday += 1
    if weekday > SUNDAY:
        weekday = MONDAY
    return weekday
So you store them as integers, convert them to strings with functions, and use screens to display the strings.
 
  • Like
Reactions: Georges.0843

Georges.0843

New Member
Oct 4, 2022
5
0
Then something like this?
Python:
default months = 12
default months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
default day = 1
default day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
default hour = 12
default am = False



label start:
    show screen time
    scene sleep
    menu optional_name:
        "Say Statement"
        "Choice 1":
            hour = +1
            if hour > 12:
                am = True
        "Choice 2":
            day = +1


screen time():
    zorder 100
    text "[day_names]"
    text "[day]"
    text "[hour]"
    if am true:
        text "PM"
    else:
        text "AM"
    text "[minutes]"
        

    return
How do I make the time advance and not repeat the same day or time?
and the next day name
also how do I define the minutes?

Sorry for my English I am using a translator.
 

MidnightArrow

Active Member
Aug 22, 2021
500
451
In your main game, call a Python function like "advance_time()" and pass it the number of minutes, hours, days, etc. that should advance. Use conditionals to check if it rolls over, and increment the next variable in line. If it's over 60 minutes, then subtract 60 and add 1 hour, etc.

Don't use "[day_names]" in your screen, that will print out the whole array. Use day_names[current_weekday]. Since the array returns a string, you don't need quotes.

If you're using AM and PM, then store the hours internally in 24-hour format, but when you pass it to the screen have a Python function that takes the integer and uses conditionals to convert it to the correct string.
 
  • Like
Reactions: Georges.0843

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,225
Alternatively to those answers, you can also dedicate five seconds of you life to search if this particular topic haven't been answered many times already. Like by example and among many others, in this thread, that one, or why not this one ?
 
  • Like
Reactions: 79flavors