Ren'Py Problem with player name and variables in Renpy replay gallery

formerflame

Newbie
Game Developer
Mar 28, 2018
89
1,102
I've been working on a replay gallery that's basically a grid with image buttons for my characters that takes them to individual character screens with image buttons using this code.

Code:
            if renpy.seen_image ( "v1dorm05" ):
                imagebutton idle "Gallery Images/c01.jpg" hover "Gallery Images/c01h.jpg" action Replay ( "introdorm" )
            else:
                imagebutton idle "Gallery Images/locked.jpg"
That code points to my main game script at a label "introdorm" and it plays until it hits $ renpy.end_replay() which I put where I want my replay to end.
That all works great. The problem is the replay doesn't show the player's name it shows it as [playername] and if there is any variables like if I assign points and there is a check for points in the replay it just errors out as undefined.

The code I'm using to define the character's name is
Code:
define MC = Character("[playername]", color="#2A4B7C")
Then during gameplay
Code:
    $ playername = renpy.input("\"What is your name?\" (default Matt)", length=15)
    $ playername = playername.strip()
    if playername == "":
        $ playername = "Matt"
That works in the game but not in replays. Does anyone know how to do this? My thoughts are probably having to create another rpy file that is just copy/paste the scenes for replay and manually assign max points. But I don't know how to do the code so it will prompt for a name once then save it so any subsequent visits to replay it won't ask for the players name again. I'm still a novice at programming.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,557
2,170
That's the thing with replays, you can't rely on the value of any variable.
It's not using a save game or anything like that... it's just going to that label blind.

The say:
To take advantage of the replay mode, a scene should begin with a label, and end with a call to renpy.end_replay(). The scene should make no assumption as to the state of the layers or variables, which can be very different in normal and replay mode.

Your best bet might be to use a to copy the name of the player after they have entered it, then when replaying - set your playername variable to match the value stored in that persistent variable.

Python:
default playername = "Matt"

label start:

    scene black with fade

    $ playername = renpy.input("\"What is your name?\" (default Matt)", length=15)
    $ playername = playername.strip() or "Matt"

    $ persistent.pname = playername

I'm unsure how you will have coded your gallery, I'm assuming a straight up screen. I know you can do a SetVariable() as part of a multipart action using square brackets...
action [SetVariable ("playername", persistent.pname), Replay ("introdorm")] - or something like that.

I'm sure it's possible to set a variable without being part of the action:, but I can't see a quick example while I'm typing this.

Even this has it's risks. What if one of the replays can be viewed without the player ever playing the games? (ie. before the persistent variable is set for the first time). I know, kind oddball and unlikely - but these are the sort of things that break games.

Alternatively, you could code something into the replayed scenes, using _in_replay.

Python:
label introdorm:
    if _in_replay:
        $ playername = persistent.pname

    # reset of scene

Also keep in mind... this is all variables. If your scene has values for love or corruption or anything else... you might want to expand that if _in_replay: check to "assume" certain values too.

You might want to make your replay gallery accessible from the "main menu" only and not within the "game menu". If you do use replays in the middle of an active game and you do this sort of "overriding variables during a replay"... keep in mind that the value of those variables won't be reset back to their original values when the replay ends.

A much better solution is to use if _in_replay: to bypass any code within a replay which uses variables... rather than setting variables to assumed values. Though that might not be possible, especially if you have some sort of "show stats" screen or something similar... at which point, you're back to locking the replay menu down so it only shows up on the main menu.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,787
The say:
To take advantage of the replay mode, a scene should begin with a label, and end with a call to renpy.end_replay(). The scene should make no assumption as to the state of the layers or variables, which can be very different in normal and replay mode.
Which isn't at all how it should be said, since I'm sure that most of the readers see it as : "The value of the variables have changed since the scene was played once, and then can be totally random."
But in fact, according to my own tests the variables are sent back to the start time. Which mean that they return to their default values, and those that are created in the fly do not exist during the replay.
Note: My tests were obviously limited, but the behavior is the same even if you save/load mid process.
You don't have permission to view the spoiler content. Log in or register now.


Alternatively, you could code something into the replayed scenes, using _in_replay.

Python:
label introdorm:
    if _in_replay:
        $ playername = persistent.pname

    # reset of scene
It's the solution that should be used preferably to the first you proposed. Not because it's the most elegant or less complicated, but because it will also serve to create the possibly missing variables, and adjust the values to reflect the expected state for this scene. And like it's right in start of the scene, it will be easier to verify what are the used variables and what are the expected value.
I haven't tested it, but since it's pure Ren'py, it's surely also possible to put a menu in the _in_replay action, to let the player choose what variation of the scene he want to see.

Lets say that it's a scene with the mother in a classical incest game, and if the daughter is corrupted enough, she can join the action, then the code could looks like that :
Python:
# A called label that avoid to write the assignation 
# in top of all the replayable  scenes.
label replayNames:
    $ playerName = persistent.pName
    $ motherName = persistent.mName
    $ bigSisName = persistent.bsName
    $ lilSisName = persistent.lsName
    return

# The replayable scene
label whatever:
    # It it's the replay
    if _in_replay:
        # Restore the names
        call replayNames
        # Restore the variables to the minimal value expected
        $ motherLove = 15
        # Ask which variation to play
        menu:
            "Mother alone":
                $ bigSisAtHome = False
            "Big sister join us":
                $ bigSisAtHome = True
                $ bigSisLove = 15
    # Start of the scene
    "You enter the kitchen"
    [...]
    if motherLove < 15:
        jump outOfTheScene
    "She jump to kiss you"
    [...]
    if bigSisAtHome and bigSisLove > 15:
        "[bigSisName] appear"
        [...]
    else:
        [...]
    $ renpy.end_replay()
    jump somewhereElse

A much better solution is to use if _in_replay: to bypass any code within a replay which uses variables... rather than setting variables to assumed values. Though that might not be possible, especially if you have some sort of "show stats" screen or something similar... at which point, you're back to locking the replay menu down so it only shows up on the main menu.
Oh, what an elegant solution.

For the readers, it would looks like :
Code:
label whatever:
    if _in_replay:
        call replayNames
        menu:
            "Mother alone":
                $ bigSisAtHome = False
            "Big sister join us":
                $ bigSisAtHome = True
    "You enter the kitchen"
    [...]
    # The /_in_replay/ MUST be the first tested.
    # /if/ condition are tested from left to right, and
    # the test stop once the result can be 'assumed'.
    # Therefore, wrote like this, the game will never know
    # that /motherLove/ possibly don't even exist.
    if _in_replay or motherLove > 15:
        # Initially it was a "if < 15 then jump", but it 
        # can't works with /_in_replay/. So revert the
        # condition, and just do nothing if the scene
        # can be played.
        pass
    else:
        # and if the scene can't be played, jump
        # outside as before.
        jump outOfTheScene
    "She jump to kiss you"
    [...]
    # Here it's a little more complex because there's
    # originally two conditions. You have to make one 
    # depend of the replay and the main flag (bigSisAtHome), 
    # And the other depend of the main flag and the effective 
    # value.
    if ( _in_replay and bigSisAtHome ) or ( bigSisAtHome and bigSisLove > 15 ):
        "[bigSisName] appear"
        [...]
    else:
        [...]
    $ renpy.end_replay()
    jump somewhereElse
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,787
anne O'nymous 79flavors sorry for bumping the thread, but i wanted to thank you. Because you fixed my issue !
<3
There's time like that, where you decide to do something "stupid", like writing a post only thanking someone.
Then this someone come home, turn on his computer, log in on the forum and his only notification point to this message...

this someone who come home, it's me, and I come home from a whole night in Medical Emergency (nothing really serious, don't worry)... So, you see, your message, it's exactly what I need right now, thanks you.
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,389
1,409
There's time like that, where you decide to do something "stupid", like writing a post only thanking someone.
Then this someone come home, turn on his computer, log in on the forum and his only notification point to this message...

this someone who come home, it's me, and I come home from a whole night in Medical Emergency (nothing really serious, don't worry)... So, you see, your message, it's exactly what I need right now, thanks you.
I hope you're doing well (I'm used to emergency rooms at night, I know what that can do :( )

You know for people like us who are not very good on renpy, people like you and 79flavors are real blessings.

Before I found this message I spent hours looking for a solution and thanks to you my problem was solved in minutes.

What you do is really helpful for people like me.
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,787
I hope you're doing well (I'm used to emergency rooms at night, I know what that can do :( )
It's not this bad. I past the week under painkillers, and it culminated with the night on emergency, where I've been put under morphine. So, psychologically speaking the week was hard, but in the same time, with my weak brain in regard to those things, between the fever and the medication I flied most of the time.


You know for people like us who are not very good on renpy, people like you and 79flavors are real blessings.
And people like you our reward. We don't do this to be praised, but it would be a lie to say that it don't feel good when we are thanked.

They don't know it yet, but some among you will continue their journey and in years they'll be the new us. It's them that will have the knowledge and experience, and that will share it.
 
  • Like
Reactions: UncleNanard

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,389
1,409
It's not this bad. I past the week under painkillers, and it culminated with the night on emergency, where I've been put under morphine. So, psychologically speaking the week was hard, but in the same time, with my weak brain in regard to those things, between the fever and the medication I flied most of the time.
I hope for you that it will get better.

A few years ago I was given morphine in the emergency room. Putting aside the reason I got it, it was one of the most pleasant experiences of my life.
I understand why people get hooked...

And people like you our reward. We don't do this to be praised, but it would be a lie to say that it don't feel good when we are thanked.

They don't know it yet, but some among you will continue their journey and in years they'll be the new us. It's them that will have the knowledge and experience, and that will share it.
I'm learning more and more how to use renpy and it's really nice software, it amazes me every day. But I think I should learn python, because there are some things I can't do. Especially for variables.

___
I have a question with the persistant fonction if you have the time.

That's work for a character with a default name ( define ex = Character('Exemple', color="#2fff00") but all my characters can be renamed so, i use a lot's of [] (define ex = Character('[Exemple]', image="mobyavatar", color="#2fff00"))

So i don't have the side image + if in a sentence i have [] i have an error (ex "Hello my name is [Exemple]).

Do you know what i can do for use the replay with the [] fonction ?
i tried :

if _in_replay:
$ [Exemple] = persistent.ex

But that don't work :(
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,787
I understand why people get hooked...
Oh yeah, everything feel so rightly in place and natural. I didn't slept when there, and they released me at 10AM... Yet what was still left of the morphine I had made me feel so refreshed that I decided to not bother my family (waiting for news don't made them have a better night than me) and walked the 40 minutes to my home like if I just awakened.
When you struggle hard with your life, it's surely really difficult to accept that you'll voluntarily continue to struggle. But it's the best thing to do, be sure of that reader, because the struggle you'll face when on drugs would be worse ; I know what I'm talking about.


I'm learning more and more how to use renpy and it's really nice software, it amazes me every day. But I think I should learn python, because there are some things I can't do. Especially for variables.
Knowing Python will help you goes further, but it can also be a trap at first. (Too) many authors miss the possibilities of native Ren'Py because of their knowledge in Python ; they try do it in Python without seeing that they could do it in Ren'Py language.
So, learning Python, yes, but then when you want to do something new, firstly look what is possible with Ren'Py. Sometimes it will be a bit below what you wanted, but unless you're really good with Python, "a bit below but it works in all case", is better than, "exactly what I want but I'm not sure if it really works".


Do you know what i can do for use the replay with the [] fonction ?
i tried :

if _in_replay:
$ [Exemple] = persistent.ex

But that don't work :(
It don't works because it's in fact a Ren'Py thing.
In Python, [whatever] put in a text mean nothing ; it's not a special kind of variables, like can be list, tuples and all. It's only for Ren'Py that it mean "interpolate the content of the 'whatever' variable inside this text".

Therefore, you just need to change the value of this said variable, to change what the text will be:
Code:
if _in_replay:
    $ Exemple = persistent.ex
 
  • Like
Reactions: gojira667

MrBaker

Newbie
Game Developer
May 28, 2020
81
767
Thanks so much. This helped me a lot! I was struggling with this.