Page 1 of 1

PauseAudio only works as a button, not as statement [SOLVED]

Posted: Mon Sep 27, 2021 9:16 pm
by MoonByte
What the title says

I want to pause the music at one point and it works perfectly fine when activated via a button a la this

Code: Select all

label start:
    "test for credits"
    play music cred
    "normal audio"
    screen pause:
        textbutton "Pause" action PauseAudio('music', value='toggle')
    show screen pause
    "paused music?"
But nothing happens when I do exactly the same thing as a statement

Code: Select all

label start:
    "test for credits"
    play music cred
    "normal audio"
    $ PauseAudio('music', value='toggle')
Using the button method will not work since the stop in the music is the game reacting to a thing the MC says (without the player having chosen anything) aka it's not an interactive moment.
I don't even get an error message or anything, the game just ignores the pause order and keeps playing the music. Am I missing something really dumb or is PauseAudio actually not possible to just...do?

A way to kinda force it to work is this

Code: Select all

screen pause:
        on 'show' action PauseAudio('music', value='toggle')
    show screen pause
    hide screen pause
    "paused music?"
    show screen pause
    hide screen pause
Aka, repeatedly call the empty screen to activate the toggle, but my professor used to say "if you have to constantly repeat something, there has to be an easier way to streamline it". So I assume there is a way to just...have it be statement and I don't know how to use it

Re: PauseAudio only works as a button, not as statement

Posted: Mon Sep 27, 2021 10:09 pm
by Imperf3kt
As best I can tell, the pauseAudio() action cannot be invoked by python as it is a screen action, and not a python function.

Usually the documentation offers a python alternative for screen actions, but I cannot find one for pauseAudio.


You could call a screen that has an extremely short timer. The timer would invoke the pauseAudio() action before returning.
A proper solution has been offered below.

Re: PauseAudio only works as a button, not as statement

Posted: Mon Sep 27, 2021 11:31 pm
by philat

Re: PauseAudio only works as a button, not as statement

Posted: Tue Sep 28, 2021 4:08 am
by drKlauz
This line just create action object

Code: Select all

$ PauseAudio('music', value='toggle')
To "do" action you need to call this object

Code: Select all

$ PauseAudio('music', value='toggle')()

Re: PauseAudio only works as a button, not as statement

Posted: Tue Sep 28, 2021 7:09 am
by Remix
$ renpy.run( PauseAudio('music', value='toggle') ) is the proper way to run screen Actions within Python.

Re: PauseAudio only works as a button, not as statement

Posted: Tue Sep 28, 2021 8:13 am
by drKlauz
Unless you running multiple actions or trying to run None there is no difference.

Code: Select all

def run(action, *args, **kwargs):
    """
    :doc: run
    :name: renpy.run
    :args: (action)

    Run an action or list of actions. A single action is called with no
    arguments, a list of actions is run in order using this function, and
    None is ignored.

    Returns the result of the last action to return a value.
    """

    if action is None:
        return None

    if isinstance(action, (list, tuple)):
        rv = None

        for i in action:
            new_rv = run(i, *args, **kwargs)

            if new_rv is not None:
                rv = new_rv

        return rv

    return action(*args, **kwargs)
But agree, for consistency reasons using renpy.run may be good idea for generic use.

Re: PauseAudio only works as a button, not as statement

Posted: Tue Sep 28, 2021 2:03 pm
by MoonByte
Ah, so there WAS a simple solution, it was just that I didn't connect that pausing audio is a SCREEN thing xD
Thanks to all of you, you saved me from spamming screens in my game o/