Help with label callbacks

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Help with label callbacks

#1 Post by trailsiderice »

Hello,

I'm trying to change the autosave functionality so that it saves at the beginning of each label instead of saving right before each choice.
I thought the best way to do this would be through a label callback function, but it doesn't seem to work.

Here's my code:

Code: Select all

init python:
    def labelCallback(name,abnormal):

        ignored_labels = ["route_menu","splashscreen","main_menu","exit_label","main_menu_screen","save_screen"]

        if not name.startswith("_") and name not in ignored_labels:
            renpy.force_autosave()

    config.label_callback = labelCallback
still it only autosaves right before a choice. What am I doing wrong?

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1009
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Help with label callbacks

#2 Post by m_from_space »

trailsiderice wrote: Mon Feb 26, 2024 7:55 pm Here's my code:

Code: Select all

    config.label_callback = labelCallback
still it only autosaves right before a choice. What am I doing wrong?
According to the documentation, the correct variable name is config.label_callbacks (plural!) and it also expects a list.

Code: Select all

config.label_callbacks = [labelCallback]

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Help with label callbacks

#3 Post by trailsiderice »

m_from_space wrote: Tue Feb 27, 2024 1:14 am
trailsiderice wrote: Mon Feb 26, 2024 7:55 pm Here's my code:

Code: Select all

    config.label_callback = labelCallback
still it only autosaves right before a choice. What am I doing wrong?
According to the documentation, the correct variable name is config.label_callbacks (plural!) and it also expects a list.

Code: Select all

config.label_callbacks = [labelCallback]
I tried that too, unfortunately that also doesn't work.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1009
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Help with label callbacks

#4 Post by m_from_space »

trailsiderice wrote: Tue Feb 27, 2024 1:54 am I tried that too, unfortunately that also doesn't work.
Put something inside the function to determine if it is called to begin with, like a renpy.notify() statement!

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Help with label callbacks

#5 Post by trailsiderice »

m_from_space wrote: Tue Feb 27, 2024 6:50 am
trailsiderice wrote: Tue Feb 27, 2024 1:54 am I tried that too, unfortunately that also doesn't work.
Put something inside the function to determine if it is called to begin with, like a renpy.notify() statement!
Huh, strangely after trying this, it's suddenly working, even though the only thing I changed was adding the renpy.notify statement. And it continues to work even after removing it.

Not sure what prevented it from working before, maybe it simply needed to recompile or something. In any case, thanks for your help!

Post Reply

Who is online

Users browsing this forum: neometalero, Ocelot