Playing sound upon screen show

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
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Playing sound upon screen show

#1 Post by computistxyz » Sat Aug 15, 2015 1:41 pm

Is there a way to make a sound effect play upon a screen being shown? For instance, an alert sound for an OK/YesNo dialogue box? I'm aware I could separately play the sound whenever that screen is called, but I was hoping there's some way of hardcoding it into the screen itself as otherwise that would require me to go back through my entire game script and menus and add in that play sound command at every single instance...

I tried adding a basic $renpy.sound.play statement in the screen for the hell of it but of course, as expected, resulted in horrendous audio glitches due to the repeating nature of screen code.

User avatar
qirien
Miko-Class Veteran
Posts: 538
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: Playing sound upon screen show

#2 Post by qirien » Tue Aug 18, 2015 7:12 pm

Here's the code I used to play a random song from a playlist when a screen is shown if the music is not already playing. It goes at the very end of the screen code. Could you use something like this?

Code: Select all

on "show" action If(renpy.music.is_playing(), true=None, false=pop_songs.RandomPlay())
Finished games:
Image
Image
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]