Rollback issue

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
bambino358
Regular
Posts: 26
Joined: Sat Apr 27, 2019 7:17 am
Contact:

Rollback issue

#1 Post by bambino358 »

I have this code for playing background music:

Code: Select all

init python:
        renpy.music.register_channel("Chan1", "sfx")
        
    init python:
        chan1play = True
    
        def queueChanCallback1():
            if chan1play:
                randomswamp = renpy.random.choice( ("audio/den/1.mp3", "audio/den/2.mp3", "audio/den/3.mp3", "audio/den/4.mp3", "audio/den/5.mp3", "audio/den/6.mp3", "audio/den/7.mp3") )
                renpy.music.queue (randomswamp, channel="Chan1", clear_queue=True, loop=False, fadein=0, tight=True)
        renpy.music.set_queue_empty_callback(queueChanCallback1, channel='Chan1')
Everything works fine but when I make a step back (rollback) it always change the background music. Is there any way to prevent rollback to change music?

Thank you

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Rollback issue

#2 Post by hell_oh_world »

bambino358 wrote: Mon Sep 16, 2019 5:31 am I have this code for playing background music:

Code: Select all

init python:
        renpy.music.register_channel("Chan1", "sfx")
        
    init python:
        chan1play = True
    
        def queueChanCallback1():
            if chan1play:
                randomswamp = renpy.random.choice( ("audio/den/1.mp3", "audio/den/2.mp3", "audio/den/3.mp3", "audio/den/4.mp3", "audio/den/5.mp3", "audio/den/6.mp3", "audio/den/7.mp3") )
                renpy.music.queue (randomswamp, channel="Chan1", clear_queue=True, loop=False, fadein=0, tight=True)
        renpy.music.set_queue_empty_callback(queueChanCallback1, channel='Chan1')
Everything works fine but when I make a step back (rollback) it always change the background music. Is there any way to prevent rollback to change music?

Thank you
This seems relevant https://www.renpy.org/doc/html/save_loa ... k_rollback

bambino358
Regular
Posts: 26
Joined: Sat Apr 27, 2019 7:17 am
Contact:

Re: Rollback issue

#3 Post by bambino358 »

Hmm... doesn't seem to work. Problem is that I don't want to dissable rollback. I just don't want rollback to activate the "function" above.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Rollback issue

#4 Post by Kia »

when you roll back, the game will run your code and choose the music at random again, if you want to keep the choice you can run the random code earlier and keep the result in a variable. this way it doesn't change while rollback.
to keep the code from restarting the music, and as an alternative solution: you can use persistent variables.

hell_oh_world please read your private messages

User avatar
Autumnotopia
Regular
Posts: 59
Joined: Sun May 19, 2019 8:53 pm
Completed: Making Friends
Tumblr: autumnotopiadev
Github: autumngreenley
itch: autumnotopia
Contact:

Re: Rollback issue

#5 Post by Autumnotopia »

I haven't tested it, but it seems to me like the in_rollback() function gives you a pretty useful tool to deal with this (if you can check if the game is rolled back before calling your function, it seems like it should do it). That said, I'm not entirely sure I understand how your music function is called so I may be off base.
Image
A game about loneliness, chess, and fighting monsters with magic

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Rollback issue

#6 Post by Imperf3kt »

Autumnotopia wrote: Mon Sep 16, 2019 11:30 pm I haven't tested it, but it seems to me like the in_rollback() function gives you a pretty useful tool to deal with this (if you can check if the game is rolled back before calling your function, it seems like it should do it). That said, I'm not entirely sure I understand how your music function is called so I may be off base.
I'm not the OP but I must say thanks a lot for pointing that out. I'm in the middle of making a blackjack game and roll back was causing all sorts of headaches.
This looks like just what I need.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Rollback issue

#7 Post by Kia »

Imperf3kt wrote: Tue Sep 17, 2019 12:37 am I'm not the OP but I must say thanks a lot for pointing that out. I'm in the middle of making a blackjack game and roll back was causing all sorts of headaches.
This looks like just what I need.
I wrote a blackjack(ish) card game for a client of mine and since it was all in a screen, rollback never became an issue. I suggest ditching the jumping and labels for the games loop and contain it inside a screen.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot]