Have a sound play a set number of times?

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
SquittenKitten
Newbie
Posts: 16
Joined: Wed Jul 17, 2019 8:51 am
Contact:

Have a sound play a set number of times?

#1 Post by SquittenKitten » Sat Jul 20, 2019 3:21 pm

I have a gunshot sound and I want it to play 5 times. How can I tell Ren'Py to let it play 5 times?

I do not want to make an extra music file where it's played 5 times to safe space.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Have a sound play a set number of times?

#2 Post by Per K Grok » Sat Jul 20, 2019 3:56 pm

SquittenKitten wrote:
Sat Jul 20, 2019 3:21 pm
I have a gunshot sound and I want it to play 5 times. How can I tell Ren'Py to let it play 5 times?

I do not want to make an extra music file where it's played 5 times to safe space.
A very simple way to do it would be

Code: Select all

    play sound "sound/bang.ogg"
    pause 0.5
    play sound "sound/bang.ogg"
    pause 0.5
    play sound "sound/bang.ogg"
    pause 0.5
    play sound "sound/bang.ogg"
    pause 0.5
    play sound "sound/bang.ogg"
    pause 0.5

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Have a sound play a set number of times?

#3 Post by Imperf3kt » Sat Jul 20, 2019 6:04 pm

Isn't there a loops=5 kwarg or something?
I didn't see it in the documentation, but I'm sure there was
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

User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Re: Have a sound play a set number of times?

#4 Post by Andredron » Sun Jul 21, 2019 12:48 am

Pfff.....

play sound.....
queue sound.....
queue sound....
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Have a sound play a set number of times?

#5 Post by IrinaLazareva » Tue Jul 23, 2019 11:54 am

Imperf3kt wrote:
Sat Jul 20, 2019 6:04 pm
Isn't there a loops=5 kwarg or something?
No, loops only takes on yes/no values.
So, loops=5 is the equivalent of loops=True
Imperf3kt wrote:
Sat Jul 20, 2019 6:04 pm
I didn't see it in the documentation, but I'm sure there was
For example, the number of cycles can be set, for transformation ( ATL). Maybe it's settled in your memory.

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Have a sound play a set number of times?

#6 Post by IrinaLazareva » Tue Jul 23, 2019 11:54 am

Anyway:

Code: Select all

label start:
    '...'
    play sound  ['bang.mp3', 'bang.mp3', 'bang.mp3', 'bang.mp3', 'bang.mp3']
    'queue of five shots'
    return
or

Code: Select all

define audio.bang = ['bang.mp3', 'bang.mp3', 'bang.mp3', 'bang.mp3', 'bang.mp3']

label start:
    '...'
    play sound bang
    'queue of five shots'
    
    play sound bang[:3]    #!  the number following the colon should not exceed the number of files in the audio.bang[] list
    'Three shots'

    play sound bang[:2]
    'Two shots'

    play sound bang[:1]  #or#  play sound bang[0]
    'single shot'    
    return

Post Reply

Who is online

Users browsing this forum: Bing [Bot]