I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

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
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#1 Post by Aureus »

Hi there.
I'm trying to be fancy with my nvl dialogue menus by introducing sub-screens with more unusual interactions attached to them. So, for example, in some cases instead of using a regular set of choices that operate on i.action, I have a special sub-screen with textbuttons that introduce variable changes, checks, automatic recoloring, branching, tooltip showcases and so on.

Code: Select all

        screen interactions_scene_prologue_01():
            $ interactions_amount = 0
            if not scene_prologue_01_observingbridge:
                $ interactions_amount += 1
                textbutton _("Examine the bridge.") action SetVariable("meta_image_single_left", "land_prologue_01"), SetVariable("meta_image_single_right", "place_prologue_bridge_01"), SetVariable("scene_prologue_01_picked", scene_prologue_01_picked+1), SetVariable("scene_prologue_01_observingbridge", 1), SetVariable("custom01", scene_prologue_01_observingbridge_description), SelectedIf(Jump("scene_prologue_01_choiceset"))
            if not scene_prologue_01_lookingattheothers:
                $ interactions_amount += 1
                textbutton _("Look at the others.") action SetVariable("meta_image_single_left", "land_prologue_01"), SetVariable("meta_image_single_right", "sprite_ziv_idle_01"), SetVariable("scene_prologue_01_picked", scene_prologue_01_picked+1), SetVariable("scene_prologue_01_lookingattheothers", 1), SetVariable("custom01", scene_prologue_01_lookingattheothers_description), SelectedIf(Jump("scene_prologue_01_choiceset"))
            if not scene_prologue_01_talkingtooctavian:
                $ interactions_amount += 1
                textbutton _("Speak with {color=#fffbe0}the guide{/color}."):
                    action SetVariable("meta_image_single_left", "place_prologue_bridge_01"), SetVariable("meta_image_single_right", "sprite_octavian_idle_01"), SetVariable("scene_prologue_01_picked", scene_prologue_01_picked+1), SetVariable("scene_prologue_01_talkingtooctavian", 1), SetVariable("custom01", scene_prologue_01_talkingtooctavian_description), SelectedIf(Jump("scene_prologue_01_octavian_choiceset"))
                    hovered SetVariable("choiceset_comment", "octavian"), Show("choiceset_comment_descriptions", transition=None)
                    unhovered SetVariable("choiceset_comment", 0), Hide("choiceset_comment_descriptions", transition=None)
            if not scene_prologue_01_observingnature:
                $ interactions_amount += 1
                textbutton _("Pay attention to the surroundings.") action SetVariable("meta_image_single_left", "place_prologue_bridge_01"), SetVariable("meta_image_single_right", "place_prologue_straightroad_01"), SetVariable("scene_prologue_01_picked", scene_prologue_01_picked+1), SetVariable("scene_prologue_01_observingnature", 1), SetVariable("custom01", scene_prologue_01_observingnature_description), SelectedIf(Jump("scene_prologue_01_choiceset"))
            if not scene_prologue_01_observingcargo:
                $ interactions_amount += 1
                textbutton _("Examine the cargo.") action SetVariable("meta_image_single_left", "land_prologue_01"), SetVariable("meta_image_single_right", "sprite_wagon_01"), SetVariable("scene_prologue_01_picked", scene_prologue_01_picked+1), SetVariable("scene_prologue_01_observingcargo", 1), SetVariable("custom01", scene_prologue_01_observingcargo_description), SelectedIf(Jump("scene_prologue_01_choiceset"))
            if interactions_amount >= scene_prologue_01_all:
                textbutton _("With no patience left, press on.") action SetVariable("custom01", ""), SelectedIf(Jump("scene_prologue_02"))
            elif interactions_amount:
                textbutton _("Join the rest of the expedition.") action SetVariable("custom01", ""), SelectedIf(Jump("scene_prologue_02"))
            else:
                textbutton _("The others give us annoyed looks.") action SetVariable("custom01", ""), SelectedIf(Jump("scene_prologue_02"))
However, because of this the game seems annoyed with the way how all of this happens mid-interaction, despite jumping to new labels and changing all sorts of variables. So if I have, for example, a set of textbuttons that involves 5 different player inputs, saving and loading the game rollbacks to the moment the "interaction" started - so before the 1st input occurred.

Therefore, the game fails to save correctly until the game leaves the current set offered by the screen and gets into actually a new "nvl" interaction.

I've been playing for hours with various ways to force renpy.restart_interaction , or ui.interact() , or adding functions to the textbuttons, or hiding and reshowing some screens. But I simply failed at everything.

Is there some sort of solution I'm missing?
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

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

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#2 Post by philat »

First of all, none of that should be in a screen - screens run multiple times for prediction and that will break horrendously.

I don't understand what you're trying to do based on your post (in an X/Y Problem sort of way). Can you explain, simply, what you are trying to do? What is the relation between these buttons and your normal nvl menu? It looks like these are simply textbuttons - why are normal nvl menu buttons not sufficient to you?

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#3 Post by Aureus »

Everything works - except for saving. I want the player to be able to pick a dialogue option, save the game, load the game, and not have the last dialogue option ignored by Ren'Py.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#4 Post by Aureus »

Bump!
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

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

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#5 Post by m_from_space »

Aureus wrote: Sun Mar 03, 2024 10:57 am Is there some sort of solution I'm missing?
Your screen is kinda freaking me out, but since that's not the question, let's ignore it. ;) I kinda also don't know what you're trying to do here.

I am not familiar with NVL, but if you open up a screen mid-interaction and want Renpy to save the changes made by interacting with the screen, you have to do the following:

Code: Select all

$ renpy.retain_after_load()
show screen interactions_scene_prologue_01
Here is the documentation for this: https://www.renpy.org/doc/html/save_loa ... after-load

On the other hand, if you want to create a checkpoint that Renpy can rollback to, use:

Code: Select all

$ renpy.checkpoint()
(https://www.renpy.org/doc/html/save_loa ... checkpoint)

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#6 Post by Aureus »

Thank you so much for your help! The first tool didn't work ("Exception: Cannot start an interaction in the middle of an interaction, without creating a new context."), but setting up the checkpoints seems to be working! It's going to save me a TON of trouble!
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#7 Post by jeffster »

Instead of using workarounds, it's much better to do a little separation of logic and presentation.
(In this case, separate a little the script and the screen).
Also it would solve problems with interactions and saving.
In a way, Ren'Py exists exactly for this purpose: to give us screens that can be used as UI instruments, not cluttered with logic:

Code: Select all

    interactions_amount = 0
label scene_prologue_01:
    call screen scene_prologue_01
    if _return == "Examine the bridge.":
        python:
            interactions_amount += 1
            meta_image_single_left = "land_prologue_01"
            meta_image_single_right = "place_prologue_bridge_01"
            scene_prologue_01_picked += 1
            scene_prologue_01_observingbridge = 1
            custom01 = scene_prologue_01_observingbridge_description
        jump scene_prologue_01

    elif _return == "Look at the others.":
        python:
            interactions_amount += 1
            meta_image_single_left = "land_prologue_01"
            meta_image_single_right = "sprite_ziv_idle_01"
            scene_prologue_01_picked += 1
            scene_prologue_01_lookingattheothers = 1
            custom01 = scene_prologue_01_lookingattheothers_description
        jump scene_prologue_01

    # And so on. Here you do the logic and either jump back to that screen,
    # or move on, depending on the conditions you set.
    # Likewise, here you can call other screens etc., and then return to the previous one or change something...

#######################

        screen scene_prologue_01():

            if not scene_prologue_01_observingbridge:
                textbutton _("Examine the bridge.") action Return("Examine the bridge.")

            if not scene_prologue_01_lookingattheothers:
                textbutton _("Look at the others.") action Return("Look at the others.")

            # And so on...

            # ...Additional menu opened on some conditions (like clicking a button):
            if some_dropdown_menu:
                vbox:
                    textbutton _("Something special 1") action Return("Something special 1")
                    textbutton _("Something special 2") action Return("Something special 2")
UI elements that take players to different "contexts" can be processed the same way: check _return and perform what they are supposed to do. E.g. change some parameters used to call this screen with various flairs.

BrentBailey
Newbie
Posts: 4
Joined: Wed Jul 13, 2022 7:52 am
Contact:

Re: I fail at forcing Ren'Py to save the changes in a screen (mid-interaction)

#8 Post by BrentBailey »

Thanks for helping me out as well.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Alex, Google [Bot], Majestic-12 [Bot]