Trying to make a sound channel loop once

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
Prince Manic
Newbie
Posts: 6
Joined: Sat Apr 11, 2015 3:35 am
Projects: Phoennix Wright AA Cases
Contact:

Trying to make a sound channel loop once

#1 Post by Prince Manic »

As I'm working on unreleased betas of my own Recreation of the Phoenix Wright engine I have an issue with sound channels trying to define the sound I need to use to play once while music is playing (that's how the game is)

Should I use this and put it in the options.py

Code: Select all

renpy.music.register_channel("nature", "sfx", True)
or this?

Code: Select all

renpy.music.register_channel("sfxstab", mixer= "sfx", loop=False)
The SFX of a stab needs to play once I've tried everything ^ this was in a old wiki cookbook and nothing, what I'm doing wrong here?

I've tried everything to make it loop once and stopping the music would be crazy as the real game doesn't stop when a sound is played.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Trying to make a sound channel loop once

#2 Post by PyTom »

What do you mean by "loop once"? Do you mean play once, or play twice?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Prince Manic
Newbie
Posts: 6
Joined: Sat Apr 11, 2015 3:35 am
Projects: Phoennix Wright AA Cases
Contact:

Re: Trying to make a sound channel loop once

#3 Post by Prince Manic »

PyTom wrote:What do you mean by "loop once"? Do you mean play once, or play twice?
I mean from loop once it plays just one time without repeating itself, I'm sure the music has to go to make it work as it defines only one channel at a time.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trying to make a sound channel loop once

#4 Post by trooper6 »

Is there a reason why you are registering your own channel rather than just using the default channels?
According to the documentation, the music channel loops by default, and the sound channel doesn't by default.

So you could just:

Code: Select all

play sound "sfxstab.mp3"
That would play that file only once on the sound channel.

Here is the documentation on audio:
http://www.renpy.org/doc/html/quickstar ... -and-sound
http://www.renpy.org/doc/html/audio.html#audio
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Prince Manic
Newbie
Posts: 6
Joined: Sat Apr 11, 2015 3:35 am
Projects: Phoennix Wright AA Cases
Contact:

Re: Trying to make a sound channel loop once

#5 Post by Prince Manic »

trooper6 wrote:Is there a reason why you are registering your own channel rather than just using the default channels?
According to the documentation, the music channel loops by default, and the sound channel doesn't by default.

So you could just:

Code: Select all

play sound "sfxstab.mp3"
That would play that file only once on the sound channel.

Here is the documentation on audio:
http://www.renpy.org/doc/html/quickstar ... -and-sound
http://www.renpy.org/doc/html/audio.html#audio
Tried it at this part

Code: Select all

show Time
    play stab "sounds/sfx-stab.wav"
- unless it should be by the character label I'm not sure I'll try something else, I have the phoenix Wright like screen shake so trying to get the sound working too.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trying to make a sound channel loop once

#6 Post by trooper6 »

Prince Manic wrote: Tried it at this part

Code: Select all

show Time
    play stab "sounds/sfx-stab.wav"
- unless it should be by the character label I'm not sure I'll try something else, I have the phoenix Wright like screen shake so trying to get the sound working too.
1) Why are you indenting after "show Time" that doesn't make any sense to me. And I'm think that'll result in some sort of problem.
2) Why are you playing "stab"? If you note what I wrote:

Code: Select all

play sound "sounds/sfx-stab.wav"
sound is the name of the default sound effects channel...so why aren't you using that?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Prince Manic
Newbie
Posts: 6
Joined: Sat Apr 11, 2015 3:35 am
Projects: Phoennix Wright AA Cases
Contact:

Re: Trying to make a sound channel loop once

#7 Post by Prince Manic »

trooper6 wrote:
Prince Manic wrote: Tried it at this part

Code: Select all

show Time
    play stab "sounds/sfx-stab.wav"
- unless it should be by the character label I'm not sure I'll try something else, I have the phoenix Wright like screen shake so trying to get the sound working too.
1) Why are you indenting after "show Time" that doesn't make any sense to me. And I'm think that'll result in some sort of problem.
2) Why are you playing "stab"? If you note what I wrote:

Code: Select all

play sound "sounds/sfx-stab.wav"
sound is the name of the default sound effects channel...so why aren't you using that?
It's one of those effects from the game like they're shocked or something I figured it out it was this with the this as part of the code

Code: Select all

init:

    python:
    
        import math

        class Shaker(object):
        
            anchors = {
                'top' : 0.0,
                'center' : 0.5,
                'bottom' : 1.0,
                'left' : 0.0,
                'right' : 1.0,
                }
        
            def __init__(self, start, child, dist):
                if start is None:
                    start = child.get_placement()
                #
                self.start = [ self.anchors.get(i, i) for i in start ]  # central position
                self.dist = dist    # maximum distance, in pixels, from the starting point
                self.child = child
                
            def __call__(self, t, sizes):
                # Float to integer... turns floating point numbers to
                # integers.                
                def fti(x, r):
                    if x is None:
                        x = 0
                    if isinstance(x, float):
                        return int(x * r)
                    else:
                        return x

                xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]

                xpos = xpos - xanchor
                ypos = ypos - yanchor
                
                nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
                ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)

                return (int(nx), int(ny), 0, 0)
        
        def _Shake(start, time, child=None, dist=100.0, **properties):

            move = Shaker(start, child, dist=dist)
        
            return renpy.display.layout.Motion(move,
                          time,
                          child,
                          add_sizes=True,
                          **properties)

        Shake = renpy.curry(_Shake)
        
    #

#
this was from the old cookbook wiki and I used this to replicate the shake from Phoenix wright this was clashing from the defined character at the end of this

Code: Select all

pw "{color=#ffffff}{font=phoenix_sans 2.ttf} {size=16}What You Seen was a Disslove like Effect from my game and it rendered her to me the sprites will be adjdusted to be on here bigger and fit on the screen{font}{/size}" with sshake
how I could add in the sound to the shake code and make it work once I've defind it with a dollar sign?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Trying to make a sound channel loop once

#8 Post by trooper6 »

Look, that code you are using is really, really old. You should use ATL for the shake, it is modern and much easier. There are a bunch of threads about it, but this one has Alex's shake transform:
http://lemmasoft.renai.us/forums/viewto ... 50#p137350

Then you just call the shake and the sound one right after the other an they'll happen at the same time.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Prince Manic
Newbie
Posts: 6
Joined: Sat Apr 11, 2015 3:35 am
Projects: Phoennix Wright AA Cases
Contact:

Re: Trying to make a sound channel loop once

#9 Post by Prince Manic »

trooper6 wrote:Look, that code you are using is really, really old. You should use ATL for the shake, it is modern and much easier. There are a bunch of threads about it, but this one has Alex's shake transform:
http://lemmasoft.renai.us/forums/viewto ... 50#p137350

Then you just call the shake and the sound one right after the other an they'll happen at the same time.
Yeah well since it clashed with it I'll get the newer pheonix wright styled one and add in the sound needed, I'll say I'll define the sound and use it if I need to.

Post Reply

Who is online

Users browsing this forum: DewyNebula