Is there a way to toggle Auto-Forward?

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
@berration
Regular
Posts: 70
Joined: Sun Jul 15, 2007 2:36 pm
Projects: EH...
Contact:

Is there a way to toggle Auto-Forward?

#1 Post by @berration »

As someone who prefers to save myself from additional repetitive finger strain, I greatly appreciate having an auto-forward option in visual novels. I see that Ren'Py allows the user to change the speed of auto-forward (with the maximum setting stopping it entirely), but I was wondering: Is there a way to toggle it on and off...perhaps with a keystroke? It seems rather annoying to have to go into the preferences menu to adjust the slider each time I want to start and stop.
Image

delta
Epitome of Generic
Posts: 525
Joined: Sat Dec 22, 2007 12:59 pm
Projects: yes
Contact:

Re: Is there a way to toggle Auto-Forward?

#2 Post by delta »

AFM is coded rather terribly in Ren'Py by default. It's possible to code around it (I did it in KS), but it's not a one-liner.
The rest is left as an exercise for the reader.

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Is there a way to toggle Auto-Forward?

#3 Post by JQuartz »

@berration wrote:Is there a way to toggle it on and off...perhaps with a keystroke?
You can use ui.keymap in an overlay like so:

Code: Select all

init python:
    def afm_overlay():
        ui.keymap(A=ui.callsinnewcontext("toggle_afm")) #This keymap uses A. You can choose your own keymap.

    config.overlay_functions.append(afm_overlay)

label toggle_afm:
    if _preferences.afm_time== 0:
        $ _preferences.afm_time= 1 #Set to whatever speed you want
    elif _preferences.afm_time> 0:
        $ _preferences.afm_time=0
    return
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Is there a way to toggle Auto-Forward?

#4 Post by PyTom »

A better way to toggle afm is:

Code: Select all

init python:
     _preferences.afm_enable = False
     
     if not persistent.set_afm:
            _preferences.afm_time = 10 # Or something. 
            persistent.set_afm = True

     def toggle_afm():
           _preferences.afm_enable = not _preferences.afm_enable
           renpy.restart_interaction()

     def afm_woc():
           if _preferences.afm_enable:
               ui.textbutton("Auto", role="selected_", clicked=toggle_afm)
           else:
               ui.textbutton("Auto", clicked=toggle_afm)

     config.window_overlay_callbacks.append(afm_woc)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

@berration
Regular
Posts: 70
Joined: Sun Jul 15, 2007 2:36 pm
Projects: EH...
Contact:

Re: Is there a way to toggle Auto-Forward?

#5 Post by @berration »

JQuartz wrote:You can use ui.keymap in an overlay like so:
Ah, fantastic! I'd prefer not to force the user to always switch to whatever arbitrary speed I pick, but that should be easy easy enough to fix by saving the previous preference setting (if it exists) in a variable, and grabbing it from there. That much code, hopefully, I should be able to manage on my own. :wink:

Thanks a lot!

...

...Heh. Or I can just wait another minute or two for PyTom to do it for me. :lol:
Hmm, that one's going to take me a little bit longer for me to understand, but I appreciate it. I'll give it a shot.

Thanks!

--

Update: Okay, I tried this out... but I got this error:

Code: Select all

Exception: config.window_overlay_callbacks is not a known configuration variable.

While executing init code:
 - script at line 67 of C:\Renpy\Projects\Test Game/game/script.rpy
 - python at line 84 of C:\Renpy\Projects\Test Game/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

  File "C:\Renpy\RenPy 6.10.1\renpy\bootstrap.py", line 260, in bootstrap
  File "C:\Renpy\RenPy 6.10.1\renpy\main.py", line 255, in main
  File "C:\Renpy\RenPy 6.10.1\renpy\execution.py", line 230, in run
  File "C:\Renpy\RenPy 6.10.1\renpy\ast.py", line 557, in execute
  File "C:\Renpy\RenPy 6.10.1\renpy\python.py", line 928, in py_exec_bytecode
  File "C:\Renpy\Projects\Test Game/game/script.rpy", line 84, in <module>
  File "C:\Renpy\RenPy 6.10.1\renpy\store.py", line 66, in __getattr__
Exception: config.window_overlay_callbacks is not a known configuration variable.
Image

aoarashit
Regular
Posts: 66
Joined: Sun Oct 11, 2009 12:22 pm
Contact:

Re: Is there a way to toggle Auto-Forward?

#6 Post by aoarashit »

I dunno if it helps, but you can implement PyTom's code to other buttons; for example, my ui.imagebuttons.

Code: Select all

               
        def outside_button():
            if show_outside_button:

                 if _preferences.afm_enable:
                    ui.imagebutton("imagebu/afw1.png","imagebu/afw2.png",xalign=0.425, yalign=0.99, role="selected_",clicked=toggle_afm)
                else:
                    ui.imagebutton("imagebu/afw1.png","imagebu/afw2.png",xalign=0.425, yalign=0.99, clicked=toggle_afm)

        config.overlay_functions.append(outside_button)
You probably can do the same for ui.textbuttons and such.

Actually I have a related question to this. The toggle on/off works beautifully; however I set the speed to 10 as indicated in the example, but my text goes lightning fast til I go into preferences and adjust the speed myself(in the preferences screen it is indeed set to 10. edit: actually, it displays no value(empty bar) no matter what value I write down for afm speed.). I tried changing the _preferences.afm_time value, but the speed displayed is the same.
Last edited by aoarashit on Sat Jan 02, 2010 10:59 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Is there a way to toggle Auto-Forward?

#7 Post by PyTom »

The code I gave above will set it once, and then leave it up to the user to set. If you want Ren'Py to set it twice, you'll have to clear persistent.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

aoarashit
Regular
Posts: 66
Joined: Sun Oct 11, 2009 12:22 pm
Contact:

Re: Is there a way to toggle Auto-Forward?

#8 Post by aoarashit »

I cleared persistent all the time I fixed the speed. Seems to be the same no matter what I put...

Quite weird, since it worked fine the first time around when I just used just

Code: Select all

ui.imagebutton("imagebu/afw1.png","imagebu/afw2.png",xalign=0.425, yalign=0.99, clicked=toggle_afm
alone as an experiment.

After I put in the else and if, the text started forwarding fast. Like I said, I deleted persistent every time. I erased the else and if and tried one more time, and now the text speed does not seem to be working either @_@ Must have mad a major screwup somewhere.

+added: Solved.
I either put

1.
if not persistent.set_afm_time:
_preferences.afm_time = 10
persistent.set_afm_time = True

(added in _time for the first and third line, from cookbook)

or

2. or deleted all afm codes, set persistent.set_afm_time=False and deleted persistent.(according to JQuartz's reply to an old thread)
Glad I got that out of my mind :)

Post Reply

Who is online

Users browsing this forum: AWizardWithWords, Ocelot, piinkpuddiin