is it possible to set up sound lists that play at random intervals and volumes?
My next project will depend on it... and I could not find anyone else who has asked such a question.
And thank you all again for helping me finish my last small project! "If One Thing Changed"
Random sounds at random intervals and volumes?
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.
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.
-
- Regular
- Posts: 62
- Joined: Thu Apr 13, 2017 6:47 am
- Contact:
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Random sounds at random intervals and volumes?
As far as I am aware, there is currently no 'good' way to achieve this. You may be able to do it using a random number generator, but it'll be very finicky code and would probably break easily.
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Ocelot
- Lemma-Class Veteran
- Posts: 2402
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Random sounds at random intervals and volumes?
I am not going to write any code right now, but I will point to functions you can use to accomplish what you want:
1) renpy.music.set_queue_empty_callback can be used to constantly queue new sounds.
2) renpy.music.queue to add sounds to play next.
3) renpy.music.set_volume to change sound volume before you queue it
4) A pseudo filename <silence x.x> to play silence (aka pause between sounds). Note that you can dynamically generate this string (probably in your callback function)
1) renpy.music.set_queue_empty_callback can be used to constantly queue new sounds.
2) renpy.music.queue to add sounds to play next.
3) renpy.music.set_volume to change sound volume before you queue it
4) A pseudo filename <silence x.x> to play silence (aka pause between sounds). Note that you can dynamically generate this string (probably in your callback function)
< < insert Rick Cook quote here > >
-
- Regular
- Posts: 62
- Joined: Thu Apr 13, 2017 6:47 am
- Contact:
Re: Random sounds at random intervals and volumes?
Thank you much for the responses, I will look into this to see if I can understand it, @_@
-
- Regular
- Posts: 62
- Joined: Thu Apr 13, 2017 6:47 am
- Contact:
Re: Random sounds at random intervals and volumes?
the queue allows me to place them to play in order, but I am trying to create an atmosphere where random things play at different volumes.
is it possible to have a variable that continuously runs and changes volume constantly, playing a sound, that has a varible that changes the next in que,
so when called it picks the random volume and the current queue song?
vol = Rand 0.2-0.4
VAriaable sound volume = volume set "vol"
loop
sound = queue list
VAriaable sound queue = change next song in queue
loop
Label play
vol - calls current volume
play song - plays current on queue.
I can't write code from scratch...
is it possible to have a variable that continuously runs and changes volume constantly, playing a sound, that has a varible that changes the next in que,
so when called it picks the random volume and the current queue song?
vol = Rand 0.2-0.4
VAriaable sound volume = volume set "vol"
loop
sound = queue list
VAriaable sound queue = change next song in queue
loop
Label play
vol - calls current volume
play song - plays current on queue.
I can't write code from scratch...
- Ocelot
- Lemma-Class Veteran
- Posts: 2402
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Random sounds at random intervals and volumes?
Here is a basic example of how you can achieve this:
1) Create a new project and replace content of script.rpy with this:
2) Download and extract it in the game directory.
3) Launch the game and listen to the sounds.
1) Create a new project and replace content of script.rpy with this:
Code: Select all
define sounds = ['sounds/explosion.wav', 'sounds/glass.wav', 'sounds/shot.wav']
init python:
def s_callback():
if s_callback.queue_silence:
silence = "<silence {0}>".format(renpy.random.random() * 2 + 0.5)
renpy.sound.queue(silence)
else:
renpy.sound.set_volume(renpy.random.random())
renpy.sound.queue(renpy.random.choice(sounds))
s_callback.queue_silence = not s_callback.queue_silence
s_callback.queue_silence = False
renpy.sound.set_queue_empty_callback(s_callback)
label start:
"Just sit here and listen to the sounds"
return
3) Launch the game and listen to the sounds.
< < insert Rick Cook quote here > >
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], Yahoo [Bot]