[Solved] Checking whether rollback/rollforward is possible

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
User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

[Solved] Checking whether rollback/rollforward is possible

#1 Post by SethRiley »

Greetings (^_^)/

I have two buttons in the quick menu like so:

◄ one rolls back; the other rolls forward ▶

It would be nice if these buttons would disappear accordingly when there is nothing to roll back/forward to (ie: on the first and final page of the dialogue).

Is there perhaps a code to check whether a rollback/rollforward is possible?

So far no luck spitting through the documentation, though I have not given up.

Does anyone know if such a code exists?
Last edited by SethRiley on Tue Mar 21, 2017 9:20 pm, edited 1 time in total.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Checking whether rollback/rollforward is possible

#2 Post by indoneko »

edit : nevermind...
My avatar is courtesy of Mellanthe

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: Checking whether rollback/rollforward is possible

#3 Post by SethRiley »

Lol, missed your reply indoneko. Almost curious what you said...

I've found "renpy.can_rollback()", which returns True if a rollback is possible.

For rolling forward there does not seem to be such a code.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Checking whether rollback/rollforward is possible

#4 Post by indoneko »

Okay... I was about to post this, but I'm not sure if this is what you want...

Code: Select all

                showif renpy.can_rollback():
                    imagebutton idle "gui/lucy_orb.png" action Rollback()
                showif renpy.roll_forward_info():
                    imagebutton idle "gui/eileen_orb.png" action RollForward()
My avatar is courtesy of Mellanthe

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: Checking whether rollback/rollforward is possible

#5 Post by SethRiley »

Thank you indoneko, that is very close indeed.

Code: Select all

        if renpy.can_rollback():
            imagebutton idle "gui/arrow_back.png" xpos 27 ypos 324 action Rollback()
does the trick fine: the rollback button disappears on the first page of dialogue. As for "renpy.roll_forward_info():", that returns True if you have already visited the next page.

I'm trying to figure out if there is a way to make the rollforward button disappear as soon as it reaches a return statement in the script...

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: Checking whether rollback/rollforward is possible

#6 Post by SethRiley »

Just thought of a workaround. Might just use a transparent image for the actual button, and have the rollforward button included in a background image or sprite of sorts.

Or I could obscure the rollforward button visually with an image on the last page of dialogue.

Seems like a crude solution though.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#7 Post by philat »

Haven't tested, but perhaps renpy.in_rollback(). Take a look around the documentation around rollback for more ideas. https://www.renpy.org/doc/html/save_loa ... n_rollback

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#8 Post by SethRiley »

Just thought of a relatively neat solution that works.

In script.rpy I added a line that says "define showforwardbutton = True". Then the following in the quick menu section in screens.rpy

Code: Select all

        if renpy.can_rollback():
            imagebutton idle "gui/arrow_back.png" xpos 27 ypos 324 action Rollback()
            
        if showforwardbutton:
            imagebutton idle "gui/arrow_forward.png" xpos 1187 ypos 324 action RollForward()
Finally, I just have the rollforward button show up and disappear with "$ showforwardbutton = True" and "$ showforwardbutton = False" at desired points in the script. :o

philat: "renpy.in_rollback()" returns True if the game has been rolled back. Sadly, there seems to exist no code to check whether a rollforward is possible.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#9 Post by philat »

Perhaps I'm misunderstanding what you mean by rollforward. I understood it to mean to rollforward while in rollback to the point you had last progressed to -- i.e., the action that is normally mapped to mousewheeldown. If you are not in rollback (= you are at a point where you have to click to continue), then you should not be able to rollforward -- by default, mousewheeldown will do nothing. I mean, if you're talking about something else, then that's something else, I suppose. *shrug*

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#10 Post by SethRiley »

Yes, forgive me for being unclear. I meant progressing, rather then rolling forward to a point that had been previously visited. For that purpose "renpy.roll_forward_info()" can be used.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#11 Post by indoneko »

I think a CTC button will fit your needs better than roll-forward button...
My avatar is courtesy of Mellanthe

User avatar
SethRiley
Regular
Posts: 35
Joined: Sat Mar 18, 2017 3:27 pm
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#12 Post by SethRiley »

A Click to Continue button is indeed what I'm talking about.

To make such a button disappear when you reach the end of the dialogue, you would need to be able to check whether there is more dialogue ahead to continue to.

Edit: For example by checking one line ahead in the script to see if a return statement is coming up next.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: [Solved] Checking whether rollback/rollforward is possib

#13 Post by indoneko »

I don't think you really need to check if the dialogue page is empty, since the CTC button is different from back button : you can keep clicking CTC until you return to main menu, but you can't do that with back button (at least not by default).

CTC usually added as a reminder for the player to click their mouse (or hit the keyboard) to advance the game (or to return back to the main menu if that was the end of your story). You don't even have to hide this button (and the whole quick menu that came with it) except for special occasion like when you have an animated scene - where you don't want those buttons to distract the player during the cutscene.
My avatar is courtesy of Mellanthe

Post Reply

Who is online

Users browsing this forum: Bing [Bot]