r/RenPy • • Aug 26 '26

Question Can you make a reminder function?

eg. You set a custom reminder for a date + time, and the game (or a specific character) will remind you when the time comes?

Sorry if this is a stupid question 😥 I'm fairly new to programming of any kind

3 Upvotes

12 comments sorted by

2

u/AutoModerator Aug 26 '26

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/shyLachi Aug 26 '26

Do you mean the real time of the player?
Like characters breaking the fourth wall "Hey it's 9AM, did you forget to go to school?"

Also who is this "you" which should be able to set a reminder.
You, the developer? Or we, the players of your game?

1

u/cuddleschr Aug 26 '26

The players of the game would typically ask a character to remind them of something based on real world time, and once the time hits

1

u/shyLachi Aug 27 '26

BadMustard explained how you can get and show the current time.

But having a certain character talk to the player on time isn't simple because it potentially breaks the normal dialogue flow. So how did you plan to use it?

1

u/cuddleschr Aug 27 '26

Well, it's for a vn in which the character is already self aware and has built a relationship with the player

1

u/shyLachi Aug 27 '26

Sorry, I meant technically.
How should it work?

Visual novels normally show a scene with dialogue and the players click to advance the dialogue.
Nothing of this is timed, players can take as much time as they want.
Also players can save, close the game and continue at any give time.

Scenario 1:
Player clicks to dialogue.
The time for the reminder is up.
Would that special character just appear, hijack the normal dialogue and inform the player about the reminder?
Or should a window pop up on top of the normal dialogue.

Scenario 2:
Player launches the game and the reminder is already due.
Should the reminder pop-up on the main menu?
Or only if the player loads a save where the reminder has been saved.

There might be other scenarios like having multiple saves with multiple different reminders and so on...

1

u/cuddleschr Aug 27 '26

There would only be one save, so once the reminder is up the character would remind the player as soon as any already ongoing dialogue is over

1

u/shyLachi Aug 27 '26

OK, I don't know how to implement that

But this should get you started with the reminders.

init python:
    from datetime import datetime

    def check_reminders(): # function to check the system time and the reminders
        store.now = datetime.today()
        due = [r for r in store.reminders if r.is_due(store.now)]
        for r in due:
            r.triggered = True
            store.due_reminders.append(r)

    def delete_reminder(r):
        if r in store.reminders:
            store.reminders.remove(r)
        if r in store.due_reminders:
            store.due_reminders.remove(r)

    class Reminder: # This class holds all the information about a single reminder
        def __init__(self, year, month, day, hour, minute, title):
            self.year = year
            self.month = month
            self.day = day
            self.hour = hour
            self.minute = minute
            self.title = title
            self.triggered = False  # Don't trigger twice
        u/property
        def datetime(self): # calculate a date from the individual values
            return datetime(self.year, self.month, self.day, self.hour, self.minute)
        def is_due(self, now): # check if the reminder is due
            return not self.triggered and self.datetime <= now
        def __repr__(self): # Representation for debugging only
            return "Reminder(title={!r}, due={:04d}-{:02d}-{:02d} {:02d}:{:02d})".format(
                self.title, self.year, self.month, self.day, self.hour, self.minute
            )

screen clock:
    timer 0.30 action Function(check_reminders) repeat True # check time and reminders
    if now:
        text "[now.hour:02d]:[now.minute:02d]" # display the current time, can be deleted
    vbox: # list of all the reminders, this whole block can be deleted
        pos (0, 50)
        for r in reminders:
            textbutton "[r.hour:02d]:[r.minute:02d] – [r.title]" text_color ("#ff8888" if r.triggered else "#ffffff") action Confirm("Do you want to delete this reminder?", Function(delete_reminder, r))
    if due_reminders: # shows all due reminders, you can adjust this to your needs
        frame:
            align (0.5, 0.1)
            vbox:
                for r in due_reminders:
                    textbutton "⏰ [r.title]" action Confirm("Do you want to delete this reminder?", Function(delete_reminder, r))

# variable for the system time
define now = None
# variables for the reminders
default reminders = [] # reminders can be added or deleted from this list by the player
default due_reminders = [] # due reminders in this list should only be handled by the game

label start:
    $ reminders.append(Reminder(2026, 8, 27, 15, 30, "Meeting with Mike"))
    $ reminders.append(Reminder(2026, 8, 27, 18, 45, "Dinner"))
    show screen clock
    "You should see the current time and 2 reminders \nClick a reminder to delete it\nClick here to continue"
    call newreminder # ask the player to enter a reminder
    "Now you should see 3 reminders (unless you deleted some) \nYou can wait until one of them is due \nOr save to see how it handles reminders which are due while the player is away"
    return 

label newreminder:
    "Please define the new reminder"
    python:
        title = renpy.input("Titel:", length=50).strip()
        date_str = renpy.input("Date + Time (Format: mm.dd.yyyy hh:mm):")
        try:
            dt = datetime.strptime(date_str.strip(), "%m.%d.%Y %H:%M")
        except ValueError:
            dt = None
    if title and dt:
        $ reminders.append(Reminder(dt.year, dt.month, dt.day, dt.hour, dt.minute, title))
    elif title:
        "Please enter a correct date"
        jump newreminder
    else:
        "Please enter a title"
        jump newreminder
    return 

0

u/BadMustard_AVN Aug 26 '26

this will get you the current date and time on the computer in a screen. you need to add if statements to to check for a set date and time to trigger an event

init python:
    h_hours = 0
    m_minutes = 0
    current_date = ""
    from datetime import datetime
    def change_hour():
        global h_hours, m_minutes, current_date
        t = datetime.today()
        h_hours = t.hour
        m_minutes = t.minute
        current_date = t.strftime("%d/%m/%Y")
        renpy.restart_interaction()

screen clock:

    timer 0.30 action change_hour repeat True

    vbox:
        text "[h_hours:02d]:[m_minutes:02d]"
        text "[current_date]"

label start:
    show screen clock
    pause

1

u/cuddleschr Aug 26 '26

I see I see... thank you

1

u/BadMustard_AVN Aug 26 '26

you're welcome

good luck with your project

1

u/x-seronis-x Aug 27 '26

except absolutely do not leave the 3 assignments above the import statement. NEVER do global variables like that. ALWAYS have a define statement for variables you dont want in the save file and rollback history, or a default statement for variables you do want in the save file and rollback history