Ren'Py Split this line vertically (define config.replay_scope)

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,686
For the system of "replays" that renpy has integrated I'm using this command to assign some variables so I don't have problems repeating some scenes.
Works well... The problem is that I will have to write many and I would like to know if there is any way to do it vertically.

Code:
define config.replay_scope = { "jessy_bath_times" : "4","day_numer" : "0","day" : "0","dayTime" : "0","tonysex" : 10,"olivia_sx" : "13"}
Thanks in advance.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
The problem is that I will have to write many and I would like to know if there is any way to do it vertically.
You mean like this ?
Python:
# You use define, so it's the same behavior, and
# anyway /config.whatever/ are never saved.
init python:
    # Warn Python that it will be a dictionary
    config.replay_scope = { "jessy_bath_times" : "4"}
    # From now, as long as you just do assignation, you can
    # create entry and assign the value all in one.
    config.replay_scope["day_numer"] = "0"
    config.replay_scope["day"] = "0"
    config.replay_scope["dayTime"] = "0"
    config.replay_scope["tonysex"] = 10
    config.replay_scope["olivia_sx"] = "13"
Also note that, like Python, Ren'py will assume that it's a multi-line value if the declaration don't look finished (here there's no '}' at the end of the line, and the following line(s) are indented. Therefore you can also write :
Code:
define config.replay_scope = { "jessy_bath_times" : "4","day_numer" : "0","day" : "0",
    "dayTime" : "0","tonysex" : 10,"olivia_sx" : "13"}
or:
Code:
define config.replay_scope = { "jessy_bath_times" : "4",
                                               "day_numer" : "0",
                                               "day" : "0",
                                               "dayTime" : "0",
                                               "tonysex" : 10,
                                               "olivia_sx" : "13"}
If you'll want or need more than one context for the replay, depending of the scene by example, you can also have something like this :
Code:
init python:
    replayContext = {}
    replayContext["thisContext"] = { "jessy_bath_times" : "4","day_numer" : "0","day" : "0",
               "dayTime" : "0","tonysex" : 10,"olivia_sx" : "13"}
    replayContext["thatContext"] = { "jessy_bath_times" : "42","day_numer" : "99","day" : "10",
               "dayTime" : "1","tonysex" : "small :p","olivia_sx" : "9001"}

[...]
label whatever:
    menu:
        "In what context do you want to see the scene ?"
        "this context":
            config.replay_scope = replayContext["thisContext"]
        "that context":
            config.replay_scope = replayContext["thatContext"]
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,686
Perfect!

I've used this solution:
Code:
    define config.replay_scope = { "jessy_bath_times" : "4",
        "day_numer" : "0",
        "day" : "0",
        "dayTime" : "0",
        "tonysex" : 10,
        "olivia_sx" : "13"}
But it's always good to know all the options.

As always, thank you very much! ;)
 

GleenXstudio

EraStorm Dev
Game Developer
Dec 22, 2018
440
4,204
I would like to dig out an old thread because I really don't get how this feature works in Renpy. I tried so many things and I must be missing something because nothing at all works with the different solutions provided before.

First, I don't get why the variables are sometimes under "..." , sometimes not, sometimes ["..."], sometimes "[...]", it makes no sense at all to me.

Let's use concrete examples, because it's the main problem of Renpy documentation, on many occasions, it's so theoretical and unpractical.

#main script variable definition
Python:
default m_score = 50
default r_score = 50
default n_score = 50

define x = Character("[player]", image="player", color="008080")

$ player = renpy.input("Enter your name")
$ player = player.strip()

$ m_score += 2
$ r_score += 1
$ n_score += 3
#replay room script
Python:
screen collectEND:
    tag menu
    add "EndingsCollection.jpg"
    grid 2 2:
        xfill True
        yfill True

        textbutton "{size=+50}{color=F1BF00}A{/color}{/size}" action Replay("END_A", scope={}, locked=None) xalign 0.5 yalign 0.75
        textbutton "{size=+50}{color=F1BF00}B{/color}{/size}" action Replay("END_B", scope={}, locked=None) xalign 0.5 yalign 0.75
     
        textbutton "{size=+50}{color=F1BF00}D{/color}{/size}" action Replay("END_C", scope={}, locked=None) xalign 0.5 yalign 0.75
        textbutton "{size=+50}{color=F1BF00}E{/color}{/size}" action Replay("END_D", scope={}, locked=None) xalign 0.5 yalign 0.75

From there, here are the questions I have :

1/ Where do I put the define config.replay_scope ? In the main script? in replay script? Doesn't matter?
define config.replay_scope = {"player": "[player]", "m_score" : 100, "r_score" : 100, "n_score" : 100}

2/ should I put the variables under "" or not? I don't get why in the examples upstairs the numbers are defined as text under " ", for me it would be logical that they remain as numbers

3/ In my replay scenes, the MC is always called [player] no matter what I do, how to transfer the chosen nickname to the replay as well?

4/ I don't understand what I should write in this function to transfer the variables to the replay scenes :
action Replay("END_A", scope={}, locked=None)


I would appreciate it very much if I could get answers using code examples (and not theoretical explanations like sadly Renpy.Org tends to do), because I don't know if any of you could manage to understand and code something from just this (if you did, you must be a genius ^^). Thanks in advance.

#stingy renpy documentation
define config.replay_scope = { “_game_menu_screen” : “preferences” }
A dictionary mapping variables in the default store to the values the variables will be given when entering a replay.

Replay(label, scope={}, locked=None)
An action that starts label as a replay.
scope
A dictionary mapping variable name to value. These variables are set when entering the replay.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
1/ Where do I put the define config.replay_scope ?
Wherever you want. It's a configuration variable, declared with . Therefore the value will be assigned at init time, like said by the doc.


2/ should I put the variables under "" or not?
It depend, are they ?


I don't get why in the examples upstairs the numbers are defined as text under " ", for me it would be logical that they remain as numbers
I just copied the values as OP gave them. And since one ("tonysex") is expressed as integer, I assume that the others have a good reason to be strings.


3/ In my replay scenes, the MC is always called [player] no matter what I do, how to transfer the chosen nickname to the replay as well?
It don't works because there's three errors in your "player": "[player]". It will feel relatively obvious for those who'll see what are the errors, but explaining them is something else...

When you put something between brackets into a screen, for Ren'Py it mean that it will have to perform an . It will be replace this part of the text by the value stored in the variable which name is between the brackets. Therefore here, your "[player]" mean, "hey, Ren'Py, here put the value of the variable named player".

So, the first error is to use this syntax when you assign a value to "player" ; technically you are defining a string, not a text to display.

The second error is the (relative) circular reference that you are creating.
You define the character like this define x = Character("[player]", [...]). Then you give to "player" the value "[player]"...
What mean that you're asking Ren'Py to replace "[player]" by the value of the variable "player" ; value that Ren'Py would have to replace by the value of "player" if it was doing recursive interpolation (what is possible but by chance not the behavior by default).

The third error is purely logical. You're trying to assign its own value to a variable ; what you wanted to do should have been wrote "player": player to works, and then the uselessness of this part would become more than obvious.


4/ I don't understand what I should write in this function to transfer the variables to the replay scenes :
action Replay("END_A", scope={}, locked=None)
The dictionary exist precisely so that you don't have to assign variables when you start the replay.
But if really you need to assign a particular variables, then it's that you've to do it.


I would appreciate it very much if I could get answers using code examples (and not theoretical explanations like sadly Renpy.Org tends to do),
I haven't provided code examples, and there's a really significant reason for this: your "player": "[player]" error.

It clearly show that you just copy/paste code without taking the time to understand what it's doing. And I say "clearly", because the errors in it are really something obvious.
While probably many would have missed it in your code (cognitive bias: "I already have difficulty debugging my code, so I don't have the level to debug someone else code"), in their own code they would have quickly understood what was wrong. You copied the part of the Character declaration, just knowing that it's how it should be wrote, but without knowing why it's wrote that way. Else you wouldn't have used this syntax, and quickly came to the conclusion that you're assign a variable to itself.

So, I answered your questions, in a way that is relatively easy to understand, and while providing the corresponding link to the documentation. The rest is up to you, and just you.


because I don't know if any of you could manage to understand and code something from just this (if you did, you must be a genius ^^).
There's 4166 games made by Ren'Py available just here. Half of them, if not more, are made by people like you, who had no coding knowledge prior to this. So, I guess that they manage to understand and code something just from the doc ; with sometime some external help when it come to effectively technical parts.

And I doubt that they are all genius. They just take the time to think about what they read, what it can mean, and try to see if they understood it correctly. While I'm among the firsts to admit that the documentation is clearly wrote for people who have at least a basic knowledge in coding, most of it is also not too difficult to understand ; nothing that few minutes of trial and error codding can't fix.
After near to five years providing help here, I can affirm that the most common issue regarding Ren'Py is "not knowing that 'this' is possible", and not "how the hell this thing works".