How to setup game state for scene replay?

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
Regis
Newbie
Posts: 16
Joined: Tue Jan 10, 2017 6:31 pm
Contact:

How to setup game state for scene replay?

#1 Post by Regis »

Hello,
I want to implement a scene gallery for my game.
According to docs RenPy already have main parts of what I need.
However it's a bit unclear how to properly setup game state. The problem is that most part of my game state initialized after "start" (to avoid some issues with save/load). I was unable to figure out how to perform same state initialization for scene replay.

Code: Select all

label start:
    call init_game_state
    jump actual_game_start_label

# Game scene setup
label init_my_game_state:
    $ e = Character("Eileen")
    $ custom_class = object()
    $ some_other_object = []
    return

# I call this label when want to trigger scene replay
label test_replay:
    "Text before replay start"

    # This is attempt to setup "clean" game state
    python in replay_store:       
        renpy.call("init_my_game_state")

    # Attempt to start replay we that "clean" game state. Obviously fails because "call_replay" expect dictionary with values, not store object
    $ renpy.call_replay("scene_to_replay", scope=replay_store)

    "Text after replay end"
    return

# Scene to be replayed
label scene_to_replay:
    "Replay text 1"
    e "Hello" # Access to object initialized in init_my_game_state
    "Replay text 2"
    return
Any ideas/suggestions how to create and pass scope with proper variables to the call_replay?

Regis
Newbie
Posts: 16
Joined: Tue Jan 10, 2017 6:31 pm
Contact:

Re: How to setup game state for scene replay?

#2 Post by Regis »

Implemented a workaround using utility label that initializes state and passes control to actual replay scene:

Code: Select all

label start:
    call init_game_state
    jump actual_game_start_label

label init_my_game_state:
    $ e = Character("Eileen")
    $ custom_class = object()
    $ some_other_object = []
    return

label test_replay:
    "Text before replay start"
    $ renpy.call_replay("_replay_init", scope=dict(_actual_in_replay="scene_to_replay"))
    "Text after replay end"
    return

# Utility label to init game state
label _replay_init:
    call init_my_game_state
    $ renpy.store._in_replay = _actual_in_replay
    jump expression _in_replay

label scene_to_replay:
    "Replay text 1"
    e "Hello"
    "Replay text 2"
    return

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: How to setup game state for scene replay?

#3 Post by gas »

Mumble mumble... your solution seems to work. But...just 2 words.
if the game change his own behaviour based on player inputs, like in a dating sim, it's quite obvious a replay scene gallery doesn't fit. In those kinda games, the replay are all about fixed events and fixed endings.
It's a matter of logic: the scene gallery will be tied to a saved game instead of being absolute. How can the gallery store and display all possible variations? Or player choose exactly what to keep and what playtrough ignore?
As for variables, you can use config.replay_scope = { } for some default when in replay.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Regis
Newbie
Posts: 16
Joined: Tue Jan 10, 2017 6:31 pm
Contact:

Re: How to setup game state for scene replay?

#4 Post by Regis »

I plan to have few groups of "scene parameters".
First group is major scene variations. Each one will need to be unlocked independently. And will be displayed as separate "subscene" in the gallery.
Second group is minor scene options. Player will be permitted to pick any combination of options before replay.
Third group is insignificant parameters. Will be set to reasonable defaults.
gas wrote:As for variables, you can use config.replay_scope = { } for some default when in replay.
Yes, I intended to use this but seems like I will have to do it a bit more complex way because some of parameters will be overridden during invocation of "init_my_game_state" in "_replay_init". Probably I will need to pass a python function to call_replay's scope to configure objects.

Post Reply

Who is online

Users browsing this forum: TimmyzFTW