I have a couple of sounds and I want them to be played randomly for the duration of a few minutes in my game.
They each take about 10-12 seconds so in order to fill a 5-7 minute mark I can't use queues.
I need them to function independently from the text boxes. How could I do that?
Is there a way to set a function to work in parallel with the text boxes?
[solved]play random sounds for a period of time
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: 33
- Joined: Sat Mar 04, 2017 8:19 am
- Contact:
[solved]play random sounds for a period of time
Last edited by Cristiander on Sun Apr 02, 2017 2:30 pm, edited 1 time in total.
Re: play random sounds for a period of time
I'm not sure how you want to "randomize" the music play... but if "shuffle" is fine, then you can call a screen that play play a music list created with MusicRoom class, and jump back to continue the dialogue (or whatever your game was doing at that time). The problem with this is that I can't no longer control what that screen is doing once I jumped. This is just a mock up.... perhaps someone else could make something better than this...
Code: Select all
screen musicbutton:
button:
text "Hit me!" size 35
background "#211"
xpos .5
ypos .5
xysize(100, 100)
action [mr.Play(), Jump("continue")]
init python:
mr = MusicRoom(fadeout=1.0, loop=False, shuffle=True) #shuffle = random, right? :D
mr.add("concerto.mp3", always_unlocked=True)
mr.add("act2_theme.mp3", always_unlocked=True)
mr.add("Love Song.mp3", always_unlocked=True)
mr.add("05 Landscaper.mp3", always_unlocked=True)
mr.add("09 Rainbow.mp3", always_unlocked=True)
label start:
"It's so quiet here. How about some music..?"
call screen musicbutton
label continue:
"Ah... this is better..."
My avatar is courtesy of Mellanthe
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3792
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: play random sounds for a period of time
Posting as a way to remind myself to supply an answer when I put my computer back together.
Here's what I would try:
You can use the playlist function to stack several sound files to play, one after the other.
Modify that to take a renpy.random value instead.
Define your audio for easy calling
Elsewhere (probably an init-1 block), define the renpy.random function.
I posted a similar function in the cookbook for multiple, random menu sounds. Perhaps it can be tweaked for your specific use.
Here's what I would try:
You can use the playlist function to stack several sound files to play, one after the other.
Modify that to take a renpy.random value instead.
Define your audio for easy calling
Elsewhere (probably an init-1 block), define the renpy.random function.
I posted a similar function in the cookbook for multiple, random menu sounds. Perhaps it can be tweaked for your specific use.
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
-
- Regular
- Posts: 33
- Joined: Sat Mar 04, 2017 8:19 am
- Contact:
Re: play random sounds for a period of time
I did some experimentation and came up with this code in the end:
Code: Select all
init:
python:
##this function creates a playlist of sounds
def sounds(songlist, lenght, channel_c, initial):
playlist = ["sounds/pause_1s.mp3"]
if initial == True:
for song in songlist:
playlist.append(song)
lenght -= 9
i = 0
while i < lenght:
for song in songlist:
ii = renpy.random.randint(0, 8)
if ii == 0:
playlist.append(song)
i += 1
return renpy.music.play(playlist, channel=channel_c)
Who is online
Users browsing this forum: DewyNebula