Stopping Python functions from "recalculating" in rollback-replays.

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
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Stopping Python functions from "recalculating" in rollback-replays.

#1 Post by ISAWHIM »

When I rollback, and then, roll forward, it doesn't give me the same "replay" results, for things which call a python function.

EG... myFunctionDiceRoll(1,6)... In replay, I don't get the original values, 1, 5, 3, 1, 2... It does going backwards 2, 1, 3, 5, 1, but going forwards from that point (rolling forward not "click-advancement"), it is re-rolling all the dice 1, 4, 1, 6, 1. Not doing as expected and replaying the prior rolls made.

How do I make it stop rerolling, or is this a bug, or intended... (I can't see it being an expected result, because you could never get back to your original location, if you just wanted to "glimpse back", and not "play a new path" by clicking back to a new location.)

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#2 Post by Errilhl »

This sounds like a coding mistake somewhere. I dunno how you do those dice-rolls, but it sounds like they're being called also when rolling back and forth (mostly forth, of course). I have something similar (not dice-rolls, but still) in my game, using renpy.random() and renpy.randomint() and they behave as expected - ie, on rollback/-forth, they display the same results, and does not get triggered again.
Currently working on: Image

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#3 Post by ISAWHIM »

Hmm... I used pythons random values... Due to needing it within python code. I didn't realize RenPy also has random values.

Yes, I assume, because it is in a function, that it is being called again, instead of pulling the value from the "store". (Might be one of those variables that they talk about, which isn't saved in the stores. I can't make heads or tails out of that help-file garble, about what is and isn't saved in game-states.)

The exact code, associated with it, is the following.

Code: Select all

    def fMoveCharacters():
        global LOC
        global CHR
        global YOU
        global TWN
        global SIS
        global ANT
        global MOM
        global DAD
        
        #40 min [8] (1563, 1843)
        #64 max [5] (1574, 1830)
        #z = Transform(xpos=1500, ypos=LOC[YOU.L][1])
        #renpy.show("ico_you", at_list=[z],layer="screens",zorder=11)
        x = 0
        for i in CHR.cCHR:
            renpy.hide("ico_" + i.cNAME.lower())
        for i in CHR.cCHR:
            if i.cNAME != "YOU":
                nm = getattr(SCH,str(i.cNAME))
                r = randint(1,len(SCH.cLOC[i.cNAME][nm[(mTime.hour*2)+int((mTime.minute+1)/30)]]))-1
                i.L = SCH.cLOC[i.cNAME][nm[(mTime.hour*2)+int((mTime.minute+1)/30)]][r]
                if renpy.get_screen("sideNavA",layer="screens") == None:
                    z = Transform(xpos=1574+x, ypos=LOC[i.L][1])
                    x += 64
                    if LOC[i.L][0] == "town":
                        renpy.show("ico_" + i.cNAME.lower(),at_list=[z],layer="screens",zorder=11)
                    else:
                        renpy.hide("ico_" + i.cNAME.lower(),layer="screens")
                else:
                    z = Transform(xpos=1574+x, ypos=LOC[i.L][1])
                    x += 64
                    if LOC[i.L][0] == "home":
                        renpy.show("ico_" + i.cNAME.lower(),at_list=[z],layer="screens",zorder=11)
                    else:
                        renpy.hide("ico_" + i.cNAME.lower(),layer="screens")
This line...
r = randint(1,len(SCH.cLOC[i.cNAME][nm[(mTime.hour*2)+int((mTime.minute+1)/30)]]))-1

The function is called after the time changes, in a function fAdvanceTime(15), at the end, after X-minutes have been calculated. Thus, the characters are now in new locations, potentially.

The code, simplified, does this...

If not YOU, in a list of all characters... Get the CHR activity, and see if there is more than one location where that activity can be done. (That is the random part.) There is either 1 or more, so it gets index 0-0 or 0-X, which tells it the characters new "location" to move to, where that activity will be done.

Code: Select all

EG, SCH.BOB=["...","relax","..."], and for BOB, there is a {dict[list]}... LOC.BOB={"relax":["bedroom","livingroom","yard"]}
What is happening, is on the roll-forward, it is triggering the function again. Thus, selecting a new location, instead of showing the last location selected, which it just rolled past, backwards in time. (It is there going backwards... with the mouse-wheel. Can't understand why it fires code at all, rolling forward. It should be reloading what it just showed going backwards.)

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#4 Post by ISAWHIM »

Here is a video of what is happening, and some further explanation of other associated code.


User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#5 Post by ISAWHIM »

This is also happening to "button-states" and my main character locations, which are RenPy variables.

Chr location... walk from...
1 = bedroom
2 = kitchen
3 = bathroom

Roll-back...
3, 2, 1 (now back in the bedroom)

Roll-forward... (Should replay 1, 2, 3, but...)
1, 1, 1 (Still in bedroom, not the bathroom)

The button-states "Selected", reflect the characters location. They go 3, 2, 1.. on rolling-back, then remain as 1, 1, 1 on rolling forward too. While everyone-else is moving around to the correct locations.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#6 Post by ISAWHIM »

I am just going to have to disable the ability to roll-back, since it doesn't work correctly at all.

It isn't doing anything correctly, unless I do anything but dialogue.

Human Bolt Diary
Regular
Posts: 111
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#7 Post by Human Bolt Diary »

As Errilhl suggested, you should be using:
https://www.renpy.org/doc/html/other.html#renpy-random

Which is a rollback safe implementation of python's random module.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Stopping Python functions from "recalculating" in rollback-replays.

#8 Post by ISAWHIM »

This has nothing to do with random... I removed that.

It is everything-else, which is python dependent, because RenPy code doesn't do what I need. Even the RenPy code doesn't roll-forward correctly.

Post Reply

Who is online

Users browsing this forum: No registered users