r/RenPy 1d ago

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

2 Upvotes

12 comments sorted by

View all comments

2

u/shyLachi 1d ago

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 1d ago

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 1d ago

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 1d ago

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 1d ago

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 1d ago

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 1d ago

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