Rollback Causing Issues with Random Events (Solved)

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
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Rollback Causing Issues with Random Events (Solved)

#1 Post by Katy133 »

I'm trying to create a random event that happens, and then creates a persistent switch (to prevent the same event from happening twice unless the player does a True Reset). The problem is that if the player Rollsback, they trigger a different random event. How do I prevent this issue from happening? I know a work-around to this would be to turn off Rollback after the random event trigger happens, but turning off Rollback is very not-user-friendly and should only be used as a last resort, if at all.

The script looks like this:

Code: Select all

label present_choice:
            #Randomly chosen. If the player has seen the picked route already, another is chosen.
            #If they have seen all of them, then the "other" event is picked:
            
            $ gift = renpy.random.choice(["event_a","event_b","event_c"])
            
            if gift == "event_a":
                if persistent.a == True:
                    jump present_choice
                "event a"
                $ persistent.a = True
            elif gift == "event_b":
                if persistent.b == True:
                    jump present_choice
                "event b"
                $ persistent.b = True
            elif gift == "event_c":
                if persistent.c == True:
                    jump present_choice
                "event c"
                $ persistent.c = True
            elif gift == "event_other":
                if persistent.a == None:
                    jump present_choice
                if persistent.b == None:
                    jump present_choice
                if persistent.c == None:
                    jump present_choice
                "Other event text."
Last edited by Katy133 on Sun May 05, 2019 3:18 pm, edited 2 times in total.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

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

Re: Rollback Causing Issues with Random Events

#2 Post by philat »

Besides the fact that I don't believe the random event resets (it shouldn't, because renpy.random is designed to work through rollback), wouldn't using persistent in this manner only allow one playthrough anyway? If the only thing you're trying to is ensure that there are no duplicates, you could just use another method like shuffle or pop to bypass using persistent variables.

User avatar
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Rollback Causing Issues with Random Events

#3 Post by Katy133 »

philat wrote: Sun Apr 21, 2019 10:40 pm Besides the fact that I don't believe the random event resets (it shouldn't, because renpy.random is designed to work through rollback), wouldn't using persistent in this manner only allow one playthrough anyway? If the only thing you're trying to is ensure that there are no duplicates, you could just use another method like shuffle or pop to bypass using persistent variables.
I'd never heard of shuffle or pop before, but I did some digging and changed the code to this:

Code: Select all

if persistent.a == None:
            jump present_choice
        if persistent.b == None:
            jump present_choice
        if persistent.c == None:
            jump present_choice
        This is the /"other/" event."
^^^This is for when the player has seen all the routes.^^^

Then I added this:

Code: Select all

label country_choice:
            #Randomly chosen. If the player has seen the picked route already, another is chosen.
            $ giftlist = ["event_a","event_b","event_b"] #List of choices
            $ renpy.random.shuffle(giftlist) #Pick from the list of choices
            $ gift = giftlist.pop() #Remembers what object from the list was picked

            if gift == "event_a":
                "gift a"
                $ persistent.a = True
            elif gift == "event_b":
                "gift b"
                $ persistent.b = True
            elif gift == "event_c":
                "gift c"
                $ persistent.c = True
Note: I'm not exactly sure what pop() does, but I get an error if I don't include it.

This fixes the rollback issue. The problem is that now the player can get the same route more than once now if they replay the game. I only want the player to be able to see each route once, and then once they've seen all of them, they get the "other" event. How do I do that? Is it something to do with the pop() line?
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

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

Re: Rollback Causing Issues with Random Events

#4 Post by philat »

pop returns and removes the item from the list. If that's not what you need, then of course you can use some other method.

Again, renpy.random should not affect rollback in your first example anyway; I don't know what you're doing to make it behave otherwise.

User avatar
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Rollback Causing Issues with Random Events

#5 Post by Katy133 »

philat wrote: Mon Apr 22, 2019 9:54 pm pop returns and removes the item from the list. If that's not what you need, then of course you can use some other method.

Again, renpy.random should not affect rollback in your first example anyway; I don't know what you're doing to make it behave otherwise.
I don't really understand what "removes the item from the list" means. Because during playtests, I'll sometimes get repeats before seeing all three events (I'll sometimes get event A twice in a row, etc). What does "removing the item from the list" mean?
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Rollback Causing Issues with Random Events

#6 Post by Katy133 »

Solved! I got help from Empish on Discord (thank you!), and this fixed the issues:

Code: Select all

$ gift_choices = set(["chocolate","vanilla","strawberry"])
    $ gift_list = list(gift_choices) #Makes a list copy of it
    call expression renpy.random.choice(gift_list) #When you want to choose a scene you use renpy.random.choice
    #And then, once it's done (so actually on the next line after the call expression line) you check for emptiness 
    #and if it is empty you just copy from the set again
    if len(gift_list) == 0:
        $ gift_list = list(gift_choices)
        
        
    #You need to indent the labels so that once the player returns, they travel to the next scene.
        label chocolate:
            "text"
            $ gift_list.remove("chocolate") #Then each scene itself will remove itself from the list at the beginning of the label
            return
            
        label vanilla:
            "text"
            $ gift_list.remove("vanilla")
            return
            
        label strawberry:
            "text"
            $ gift_list.remove("strawberry")
            return
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

Post Reply

Who is online

Users browsing this forum: Google [Bot]