[Solved] Set the volume directly into a specific defined audio file

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
Dark79
Regular
Posts: 59
Joined: Sun Apr 18, 2021 2:21 pm
Contact:

[Solved] Set the volume directly into a specific defined audio file

#1 Post by Dark79 »

Hello,

I have a question regarding to the audio volume controls especially aimed for the main menu.

I have defined an audio file like this.

Code: Select all

define audio.music_main_menu = "music_file_name.mp3"
And in the the options.rpy I set up the main menu music.

Code: Select all

define config.main_menu_music = audio.music_main_menu
The music plays fine. But I have noticed that there is really not much else I can do.
Of course I could use Audacity app and manually change the volume but I assumed I could change all that while defining the audio file.

Correct me if I am wrong but it seems like defining an audio file as a usable variable is just for that.

I assumed you could place specific settings like volume and etc into the defined audio file something like this(NOTE: the code below is not correct, it is just for the visual example):

Code: Select all

define audio.music_main_menu = Audio("music_file_name.mp3", volume = 0.3)


The config.main_menu_music also seems to only accept the audio file path name or the defined ones and there is nothing much else to do.

For the regular game flow like in the Label block content I could just write:

Code: Select all

label start:

    play audio.music_main_menu volume 0.3
	
    $ renpy.pause(hard= true) #Preventing to return to the main menu 
    return


And this is fine

But I have no idea how to approach this for the main menu unless I suppose I somehow make the music play when the main_menu screen is shown.

So is there really nothing much else you can do, like add more settings, parameters directly into defined audio file? :)
Last edited by Dark79 on Mon Nov 21, 2022 9:24 am, edited 2 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
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: Set the volume dirrectly into a specific defined audio file

#2 Post by PyTom »

You can leave config.main_menu_music as None, and do:

Code: Select all

label before_main_menu:
         play music_main_menu volume 0.3
         return
The audio. is redundant, as the play statement automatically looks in the audio namespace.
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
Dark79
Regular
Posts: 59
Joined: Sun Apr 18, 2021 2:21 pm
Contact:

Re: Set the volume dirrectly into a specific defined audio file

#3 Post by Dark79 »

PyTom wrote: Thu Nov 17, 2022 8:36 pm You can leave config.main_menu_music as None, and do:

Code: Select all

label before_main_menu:
         play music music_main_menu volume 0.3
         return
The audio. is redundant, as the play statement automatically looks in the audio namespace.
Thank you PyTom for the reply and for the solution :) .

The reason why I use "audio." is for the function renpy.music.play().

For example:

Code: Select all

    $ renpy.music.play(music_main_menu,'music', loop=True, fadeout=1.0, fadein=1.0, if_changed=True)
The function will not play the music unless I add the "audio." part

Code: Select all

    $ renpy.music.play(audio.music_main_menu,'music', loop=True, fadeout=1.0, fadein=1.0, if_changed=True)
But to be frankly honest I have been using "audio." for quite some time now(never failed so far), that I didn't bother to check again. Maybe there have been new changes within Renpy or unless I was writing the function incorrectly.

I have noticed also a problem with before_main_menu label with "if_changed" exist:

Code: Select all

label before_main_menu:
         play music music_main_menu volume 0.3 if_changed
         return
Here everything else works fine except if another label contains the same music "music_main_menu"

Code: Select all

label start:
    play music music_main_menu volume 0.3 if_changed
    $ renpy.pause(hard = True)
    return
 
And then if I return back to the main menu from the "start label", the music will restart even though it theoretically shouldn't, since "if_changed" exist in the "before_main_menu label". While defining music in "config.main_menu_music = audio.music_main_menu", the music will not restart if I return to the main menu from the "start label".

This is overall not a serious issue. Just curious with these different behaviors. :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot]