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 »

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 »

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: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

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

#3 Post by Imperf3kt »

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

Twitter

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

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

#4 Post by Andredron »

Pfff.....

play sound.....
queue sound.....
queue sound....

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 »

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 »

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: Ahrefs [Bot], Google [Bot]