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

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
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

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

#1 Post 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
Last edited by MoonByte on Tue Sep 28, 2021 2:03 pm, edited 1 time in total.

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

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

#2 Post 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.
Last edited by Imperf3kt on Tue Sep 28, 2021 4:37 pm, edited 1 time in total.
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


drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

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

#4 Post 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')()
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

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

#5 Post by Remix »

$ renpy.run( PauseAudio('music', value='toggle') ) is the proper way to run screen Actions within Python.
Frameworks & Scriptlets:

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

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

#6 Post 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.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
MoonByte
Regular
Posts: 173
Joined: Thu Mar 24, 2016 9:18 pm
Completed: Shine (RPG Maker), Heroes (RPG Maker), Lantern Bearer (RPG Maker), Loop the Loop (Unity), Other Stars (Unreal), Sky Eye (RPG Maker), WIN Delivery & Fateful (Ren'Py)
Projects: Weird Is Normal (Ren'Py)
Location: Germany
Contact:

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

#7 Post 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/

Post Reply

Who is online

Users browsing this forum: No registered users