How to stop main_menu music in options screen? [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
liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

How to stop main_menu music in options screen? [SOLVED]

#1 Post by liagel »

Hello there!

I started using Ren'Py 5 months ago, and when I had a question, bug, or problem, I used to come here and find a solution.
But not this time :) This time, I need your help Ren'Py users :P

So, I have my main menu which is a little customized, but not much:

Code: Select all

hotspot (1338, 92, 568, 73) action ShowMenu("load")
hotspot (1338, 197, 568, 73) action Start()
hotspot (1338, 301, 568, 73) action ShowMenu("gallery")
hotspot (1338, 408, 568, 73) action ShowMenu("preferences")
hotspot (1338, 516, 568, 73) action Quit()
So, nothing fancy, and in the option file, I have set my main menu music:

Code: Select all

define config.main_menu_music = "music/music.ogg"
Everything works perfectly but what I would like now, is that the main menu music stops when clicking on load link or gallery link, or preferences link...
So, I can set a new music loop for each of these pages.
I tried a lot things, even weird stuff, but I couldn't managed to stop this music..

Do you have any idea ?
thank you for your help, and sorry for my bad English :p
Last edited by liagel on Fri Jan 11, 2019 7:02 pm, edited 1 time in total.

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

Re: How to stop main_menu music in options screen?

#2 Post by Imperf3kt »

There's a few ways to achieve what you want, but personally I think the best way is to use the on show command.

Since the screens you mention are part of the game menu screen, that's the screen you need to modify. You'll also need a screen check.

Try something like this (paste it anywhere inside the game_menu screen)

Code: Select all

    if renpy.get_screen("preferences"):
        on show Play music  ("my file.ogg")
        on hide Stop music
Note that I wrote this on a mobile phone, from memory and haven't tested it for accuracy. If it doesn't work, I can check it properly later when at a PC.
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

liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

Re: How to stop main_menu music in options screen?

#3 Post by liagel »

Imperf3kt wrote: Thu Jan 10, 2019 6:23 pm There's a few ways to achieve what you want, but personally I think the best way is to use the on show command.

Since the screens you mention are part of the game menu screen, that's the screen you need to modify. You'll also need a screen check.

Try something like this (paste it anywhere inside the game_menu screen)

Code: Select all

    if renpy.get_screen("preferences"):
        on show Play music  ("my file.ogg")
        on hide Stop music
Note that I wrote this on a mobile phone, from memory and haven't tested it for accuracy. If it doesn't work, I can check it properly later when at a PC.
Thank you for your answer Imperf3kt, but unfortunately, I have a statement expected error.
I tried to intended the lines in different ways but without success.

Code: Select all

File "game/screens.rpy", line 506: expected statement.
    on--> show play music ("my file.ogg")
I got you point, I will check on this part of the code.

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

Re: How to stop main_menu music in options screen?

#4 Post by Imperf3kt »

Note that "play" must be capitalised.

I can double check I have written everything correctly in about five - six hours
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

liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

Re: How to stop main_menu music in options screen?

#5 Post by liagel »

Hello! (Morning time here now :) )

Yes, I have written Play, then I tried without capital P, the results were the same.
I have written it correctly now and I will try to check my files again this morning.

Thanks for the help!

liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

Re: How to stop main_menu music in options screen?

#6 Post by liagel »

So, I have indented well now and it seems the statement problem is gone.
I have now this error message :

Code: Select all

File "game/screens.rpy", line 390: u'show' is not a keyword argument or valid child for the on statement.
    on show play music  ("music/op3.mp3")

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

Re: How to stop main_menu music in options screen?

#7 Post by Imperf3kt »

Okay, I found some time to check what the code should be.

This is what I use in one project:

Code: Select all

    on "show" action Play("music", song)
Music tells renpy to use the music channel, which is what the main menu music plays on, so it'll stop it and play the new song without you needing to do much.
The "song" bit is the file to play. It requires this additional bit of code before the start label:

Code: Select all

define song = "my_song.ogg"
I also suggest, to start the main menu music playing again when a player returns to the main menu, it may be necessary to add one of these to the main menu as well. If you do, config.main_menu_music won't be used.

If you still need a bit of help understanding what I've posted here, just say and I'll jump on my laptop and put it together for you.
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

liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

Re: How to stop main_menu music in options screen?

#8 Post by liagel »

Imperf3kt wrote: Fri Jan 11, 2019 4:30 pm Okay, I found some time to check what the code should be.

This is what I use in one project:

Code: Select all

    on "show" action Play("music", song)
Music tells renpy to use the music channel, which is what the main menu music plays on, so it'll stop it and play the new song without you needing to do much.
The "song" bit is the file to play. It requires this additional bit of code before the start label:

Code: Select all

define song = "my_song.ogg"
I also suggest, to start the main menu music playing again when a player returns to the main menu, it may be necessary to add one of these to the main menu as well. If you do, config.main_menu_music won't be used.

If you still need a bit of help understanding what I've posted here, just say and I'll jump on my laptop and put it together for you.
Ok, I managed to make it work but it was funny.

So first, I try your code in the game menu screen:

Code: Select all

if renpy.get_screen("preferences"):
        on "show" action Play("music", song)
And I defined the "song" in script.rpy. And it works, but only for the ingame game menu. I mean, if I choose the preferences from the main menu, it doesn't change anything. But if I launch a game, and during the game, right click to have the preferences menu, then I can hear the song...

But what you've showed me was exactly what I needed for my gallery page :)

To have this to work in the main menu, I simply add the action... after the action in main_menu.
To be clear, I change this:

Code: Select all

hotspot (1338, 408, 568, 73) action ShowMenu("gallery")
to this:

Code: Select all

hotspot (1338, 408, 568, 73) action [ShowMenu("gallery"), Play("music", song)]
And it works perfectly !

of course, as you said, I had to add the same action to "return", so in gallery.rpy:

Code: Select all

.... action [Return(), Play("music", song2)].....
And of course define song2 as the main_menu music.

I don't know if I was clear, sorry for my bad English.

And thank you very much Imperf3kt, you help me a lot!

Now, I can keep going with this game :P

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

Re: How to stop main_menu music in options screen? [SOLVED]

#9 Post by Imperf3kt »

I would have expected the game menu to work but I suppose its just for ingame screens.

If you're happy with the way it works, it will work that way just fine.
Its not actually exactly what I had in mind, but the overall effect is identical I guess.

If you need further help, or need to make changes in the future, just reply and I'll see it sometime.
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

liagel
Regular
Posts: 30
Joined: Thu Jan 10, 2019 5:13 pm
Contact:

Re: How to stop main_menu music in options screen? [SOLVED]

#10 Post by liagel »

Imperf3kt wrote: Sat Jan 12, 2019 7:33 am I would have expected the game menu to work but I suppose its just for ingame screens.

If you're happy with the way it works, it will work that way just fine.
Its not actually exactly what I had in mind, but the overall effect is identical I guess.

If you need further help, or need to make changes in the future, just reply and I'll see it sometime.
Will do, thank you very much!

Post Reply

Who is online

Users browsing this forum: No registered users