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.
-
bambino358
- Regular
- Posts: 26
- Joined: Sat Apr 27, 2019 7:17 am
-
Contact:
#1
Post
by bambino358 » 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
-
hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Projects: The Button Man
- Organization: NILA
- Github: hell-oh-world
- Location: Philippines
-
Contact:
#2
Post
by hell_oh_world » Mon Sep 16, 2019 6:38 am
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:
#3
Post
by bambino358 » Mon Sep 16, 2019 6:59 am
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.
-
Kia
- Eileen-Class Veteran
- Posts: 1008
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
-
Contact:
#4
Post
by Kia » Mon Sep 16, 2019 12:15 pm
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
-
Autumnotopia
- Regular
- Posts: 59
- Joined: Sun May 19, 2019 8:53 pm
- Completed: Making Friends
- Tumblr: autumnotopiadev
- Github: autumngreenley
- itch: autumnotopia
-
Contact:
#5
Post
by Autumnotopia » 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.
A game about loneliness, chess, and fighting monsters with magic
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#6
Post
by Imperf3kt » Tue Sep 17, 2019 12:37 am
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
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
-
Kia
- Eileen-Class Veteran
- Posts: 1008
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
-
Contact:
#7
Post
by Kia » Tue Sep 17, 2019 2:35 am
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.