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.
I'm trying to make a shop screen with a character on the side that randomly talks to you, and his lips will flap when a voice clip is playing. Problem is that I can't seem to get the duration of the voice clip within the screen. I've been doing it like this:
screen shop:
## just using a key to test if this idea would work, which it doesn't
key "o" action [SetVariable('side_speaking',True)]
if side_speaking == True:
$ renpy.play('voiceclip.wav', channel='voice')
$ line_duration = renpy.music.get_duration(channel="voice")
add "shop guy speaking"
timer line_duration action SetVariable('side_speaking',False)
else:
add "shop guy"
Apparently, Renpy is just returning 0.0 for the duration which is... odd. If I set the channel to "music", it works perfectly fine with the BGM I already have playing. I've also checked if it's the voice file itself, which it isn't.
Last edited by filthsama on Wed Jul 06, 2022 12:51 am, edited 1 time in total.
I tested it in multiple ways and this seems to be a timing problem of some sort, but with a weird glitch.
One thing first though: If you have python code inside your screen, make sure to understand that the code might get executed multiple times on random occations (when Renpy deems necessary). So you should put actions into screen objects like timers, that don't repeat otherwise the sound might just play again from the beginning.
screen shop:
# create a screen variable
default line_duration = None
## just using a key to test if this idea would work, which it doesn't
key "o" action [SetVariable('side_speaking',True)]
if side_speaking:
# renpy will put all audio files found in folder "audio" into the audio object and strip the file extension
timer 0.01 action Play("voice", audio.voiceclip)
# in python this is not true for 0.0 by the way
if not line_duration:
timer 0.01 repeat True action SetScreenVariable("line_duration", renpy.music.get_duration("voice"))
else:
timer line_duration action SetVariable('side_speaking',False),SetScreenVariable("line_duration", None)
add "shop guy speaking"
else:
add "shop guy"