Music choice Interface

For discussion and support of other visual novel engines.
Post Reply
Message
Author
Oceane_Kudo
Newbie
Posts: 4
Joined: Tue Mar 22, 2022 5:09 am
Deviantart: TheXlize
Contact:

Music choice Interface

#1 Post by Oceane_Kudo »

Hello everyone! I've been working on a game and I'm trying to make a "music" section where you can choose the music on the background. There are two problems:
- The music only works in the Preferences section (where I put the music screen) and as soon as I leave the preferences, the choice disappears (I know it's probably related to the fact that there is already a song played in the background but I can't find where I can replace the song other than config.main_menu_music in options.rpy.
- The name of the song doesn't update when I click on the "<" or ">"


There's two solutions to my problem and although the first one is my number choice of esthetic, I can settle for the second one.

1st:

Code: Select all

init python:
	music_playlist = ["audio/PerituneMaterial_Guitar_Melancholy2.mp3","audio/PerituneMaterial_Poema_Guitar.mp3", "audio/PerituneMaterial_Positive.mp3", "audio/PerituneMaterial_Rapid2.mp3"]
    	music_playlist_name = ["Main theme", "Soft Guitar", "Positive", "Mini-game"]
    	current_index_playlist = 0
    	current_index_playlist_name = 0
    	def next_song():
        	global current_index_playlist, current_index_playlist_name
        	current_index_playlist = (current_index_playlist + 1) % len(music_playlist)
        	current_index_playlist_name = (current_index_playlist_name + 1) % len(music_playlist_name)
        	config.main_menu_music = [music_playlist[current_index_playlist]]
        	renpy.music.play(config.main_menu_music)
    	def previous_song():
       		global current_index_playlist, current_index_playlist_name
        	current_index_playlist = (current_index_playlist - 1) % len(music_playlist)
        	current_index_playlist_name = (current_index_playlist_name - 1) % len(music_playlist_name)
        	config.main_menu_music = [music_playlist[current_index_playlist]]
        	renpy.music.play(config.main_menu_music)

screen music_choice():
    hbox:
        label _("Music")
        hbox:
            textbutton "<" action previous_song
            text "[music_playlist_name[current_index_playlist_name]]" id "song_name"
            textbutton ">" action next_song
As I said earlier have two problems here. The first one is that each time I click for the previous or next song, the name of the music doesn't update. I know I need to put something in the next_song() section in order for it to update but I don't know what... I've tried renpy.reload_script() but it doesn't work either...

2nd:

Code: Select all

init python:
	music_choice = [("Main theme", "audio/PerituneMaterial_Guitar_Melancholy2.mp3"), ("Soft Guitar", "audio/PerituneMaterial_Poema_Guitar.mp3"), ("Positive", "audio/PerituneMaterial_Positive.mp3"), ("Mini-game", "audio/PerituneMaterial_Rapid2.mp3")]

screen music_choice():
    hbox:
        label _("Music")
        vbox:
            for choice in music_choice:
                textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]
What I don't understand here is that it should work! But I have this message from Renpy:

Code: Select all

```
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 828, in execute
    screen preferences():
  File "game/screens.rpy", line 828, in execute
    screen preferences():
  File "game/screens.rpy", line 832, in execute
    use game_menu(_("Preferences"), scroll="viewport"):
  File "game/screens.rpy", line 424, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 424, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 433, in execute
    frame:
  File "game/screens.rpy", line 436, in execute
    hbox:
  File "game/screens.rpy", line 442, in execute
    frame:
  File "game/screens.rpy", line 445, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 447, in execute
    viewport:
  File "game/screens.rpy", line 456, in execute
    vbox:
  File "game/screens.rpy", line 457, in execute
    transclude
  File "game/screens.rpy", line 832, in execute
    use game_menu(_("Preferences"), scroll="viewport"):
  File "game/screens.rpy", line 834, in execute
    vbox:
  File "game/screens.rpy", line 866, in execute
    hbox:
  File "game/screens.rpy", line 870, in execute
    vbox:
  File "game/screens.rpy", line 881, in execute
    use music_choice()
  File "game/mes_screens.rpy", line 653, in execute
    screen music_choice():
  File "game/mes_screens.rpy", line 653, in execute
    screen music_choice():
  File "game/mes_screens.rpy", line 654, in execute
    hbox:
  File "game/mes_screens.rpy", line 656, in execute
    vbox:
  File "game/mes_screens.rpy", line 657, in execute
    for choice in music_choice:
  File "game/mes_screens.rpy", line 658, in execute
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]
  File "game/mes_screens.rpy", line 658, in keywords
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]
  File "game/mes_screens.rpy", line 658, in <module>
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]
NameError: name 'chosen_music' is not defined
And even if I change the last line from "textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]" to "textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play("chosen_music")]" (the difference here in on the Play("chosen_music"), on the first one there's no " "), I still have this message:

Code: Select all

```
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 828, in execute
    screen preferences():
  File "game/screens.rpy", line 828, in execute
    screen preferences():
  File "game/screens.rpy", line 832, in execute
    use game_menu(_("Preferences"), scroll="viewport"):
  File "game/screens.rpy", line 424, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 424, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 433, in execute
    frame:
  File "game/screens.rpy", line 436, in execute
    hbox:
  File "game/screens.rpy", line 442, in execute
    frame:
  File "game/screens.rpy", line 445, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 447, in execute
    viewport:
  File "game/screens.rpy", line 456, in execute
    vbox:
  File "game/screens.rpy", line 457, in execute
    transclude
  File "game/screens.rpy", line 832, in execute
    use game_menu(_("Preferences"), scroll="viewport"):
  File "game/screens.rpy", line 834, in execute
    vbox:
  File "game/screens.rpy", line 866, in execute
    hbox:
  File "game/screens.rpy", line 870, in execute
    vbox:
  File "game/screens.rpy", line 881, in execute
    use music_choice()
  File "game/mes_screens.rpy", line 653, in execute
    screen music_choice():
  File "game/mes_screens.rpy", line 653, in execute
    screen music_choice():
  File "game/mes_screens.rpy", line 654, in execute
    hbox:
  File "game/mes_screens.rpy", line 656, in execute
    vbox:
  File "game/mes_screens.rpy", line 657, in execute
    for choice in music_choice:
  File "game/mes_screens.rpy", line 658, in execute
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play("chosen_music")]
  File "game/mes_screens.rpy", line 658, in keywords
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play("chosen_music")]
  File "game/mes_screens.rpy", line 658, in <module>
    textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play("chosen_music")]
TypeError: __init__() missing 1 required positional argument: 'file'
I dont know what is wrong here.. Can someone please help?

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Music choice Interface

#2 Post by Alex »

Oceane_Kudo wrote: Fri May 10, 2024 9:23 am

Code: Select all

init python:
	music_choice = [("Main theme", "audio/PerituneMaterial_Guitar_Melancholy2.mp3"), ("Soft Guitar", "audio/PerituneMaterial_Poema_Guitar.mp3"), ("Positive", "audio/PerituneMaterial_Positive.mp3"), ("Mini-game", "audio/PerituneMaterial_Rapid2.mp3")]

screen music_choice():
    hbox:
        label _("Music")
        vbox:
            for choice in music_choice:
                textbutton choice[0] action [SetVariable("chosen_music", choice[1]), Play(chosen_music)]
Try to specify the name of channel to play your tune with - https://www.renpy.org/doc/html/screen_actions.html#Play

giorgi1111
Regular
Posts: 43
Joined: Sat May 04, 2024 10:40 pm
Contact:

Re: Music choice Interface

#3 Post by giorgi1111 »

Define somewhere: default chosen_music = "" everything (ALLMOST) needs to be defined. if you put it in rpy it needs nothing nor int nor python

Post Reply

Who is online

Users browsing this forum: No registered users