Help with Music Room[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
HigurashiKira
Miko-Class Veteran
Posts: 832
Joined: Mon Nov 01, 2010 9:10 pm
Contact:

Help with Music Room[SOLVED]

#1 Post by HigurashiKira »

Well I decided to add a Music Room to my VN, and I really can't figure out what I do wrong, it just keeps crashing on me.

Code: Select all

 def set_playing_(track):
        store.playing = track
        return True

    set_playing = renpy.curry(set_playing_)

    # Call this with a button name and a track to define a music
    # button.
    def music_button(name, track):

        if store.playing == track:
            role = "selected_"
        else:
            role = ""

        if not renpy.seen_audio(track):
            name = "???"
            clicked = None
        else:
            clicked = set_playing(track)


        ui.textbutton(
            name,
            clicked=clicked,
            role=role,
            size_group="music")

    # Add to the main menu.
    config.main_menu.insert(3, ("Music Room", "music_room", "True"))


label music_room:

    scene bg safe

    python:
        _game_menu_screen = None

        # The default track of music.
        playing = "1-Decay.mp3"

    
    label music_room_loop:

    # Play the playing music, if it changed.
    python:
        renpy.music.play(playing, if_changed=True, fadeout=1)

        # Display the various music buttons.
        ui.side(('c', 'r'),  xpos=140, ypos=130, xanchor=0.0, yanchor=0.0, spacing=5)
        vp = ui.viewport(draggable=True, mousewheel=True, xmaximum=250, ymaximum=220)
       
        ui.vbox()
        music_button("Decay", "Decay.mp3")
        music_button("Rains will Fall", "Rains will Fall.mp3")
        music_button("Deep Noise", "Deep Noise.mp3")
        music_button("Decisions", "Decisions")
        music_button("Harmful or Fatal", "Harmful or Fatal.mp3")
        music_button("Master", "Master.mp3")
        music_button("Interloper", "Interloper.mp3")
        music_button("Kool Kats", "Kool Kats")
        music_button("Lightless Dawn", "Lightless Dawn.mp3")
        music_button("Atlantean Twilight", "Atlantean Twilight")
        ui.close()
       
        ui.bar(adjustment=vp.yadjustment, style='vscrollbar')
        ui.close()
       
       
        ui.side(('c', 'r'),  xpos=410, ypos=130, xanchor=0.0, yanchor=0.0, spacing=5)
        vp = ui.viewport(draggable=True, mousewheel=True, xmaximum=250, ymaximum=220)

        # This is how we return to the main menu.
        ui.textbutton(
            "Return",
            clicked=ui.returns(False),
            xalign=1,
            ypos=550,
            size_group="music")

    if ui.interact():
        jump music_room_loop
    else:
        return

That's the full code. A little help?
Last edited by HigurashiKira on Tue Nov 09, 2010 8:51 pm, edited 1 time in total.
I have moved to a new account. Please contact me here from now on. T/Y~

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Help with Music Room

#2 Post by Jake »

HigurashiKira wrote:Well I decided to add a Music Room to my VN, and I really can't figure out what I do wrong, it just keeps crashing on me.
Nothing glaring jumps out upon a quick scan of the code. It would be very useful to know what 'it just keeps crashing' means - do you get a traceback message? Can we see it?
Server error: user 'Jake' not found

User avatar
Formedras
Regular
Posts: 40
Joined: Sat Oct 04, 2008 3:11 am
Projects: Ninja TK
Contact:

Re: Help with Music Room

#3 Post by Formedras »

I'm not sure, since I'm not as skilled as pretty much everyone else here, but maybe it's that the music_room_loop label is incorrectly indented? (As in, it shouldn't be at all?)

Also, I'm not sure if it matters, but maybe it might be a good idea to toss that Python block into init under its own def and just activate it from music_room_loop. (Of course, this may break your program, if I'm wrong.)
http://www.google.com/profiles/tizalka
Current Project:
Ninja TK

HigurashiKira
Miko-Class Veteran
Posts: 832
Joined: Mon Nov 01, 2010 9:10 pm
Contact:

Re: Help with Music Room

#4 Post by HigurashiKira »

Code: Select all

I'm sorry, but an uncaught exception occurred.

NameError: name 'music_button' is not defined

While running game code:
 - script at line 315 of C:\Documents and Settings\Kira\Desktop\Doujin Games\Death Rule-Episode 0/game/options.rpy
 - python at line 323 of C:\Documents and Settings\Kira\Desktop\Doujin Games\Death Rule-Episode 0/game/options.rpy.

-- Full Traceback ------------------------------------------------------------

  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\bootstrap.py", line 270, in bootstrap
  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\main.py", line 310, in main
  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\main.py", line 93, in run
  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\execution.py", line 259, in run
  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\ast.py", line 574, in execute
  File "C:\Documents and Settings\Kira\Desktop\renpy-6.11.2\renpy\python.py", line 957, in py_exec_bytecode
  File "C:\Documents and Settings\Kira\Desktop\Doujin Games\Death Rule-Episode 0/game/options.rpy", line 323, in <module>
NameError: name 'music_button' is not defined

While running game code:
 - script at line 315 of C:\Documents and Settings\Kira\Desktop\Doujin Games\Death Rule-Episode 0/game/options.rpy
 - python at line 323 of C:\Documents and Settings\Kira\Desktop\Doujin Games\Death Rule-Episode 0/game/options.rpy.

Ren'Py Version: Ren'Py 6.11.2b
There's the full traceback...
I have moved to a new account. Please contact me here from now on. T/Y~

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Help with Music Room

#5 Post by Jake »

HigurashiKira wrote:

Code: Select all

NameError: name 'music_button' is not defined
Try putting an

Code: Select all

init python:
just before the beginning of the code you pasted into your earlier post, and make sure that the "def set_playing_(track):" line is indented four spaces, so that the beginning looks like this instead:

Code: Select all

init python:
    def set_playing_(track):
If that first line actually isn't indented in your code file, that's part of your problem - and putting it in an init block makes sure that that code gets run (and the music_button method defined) before it starts your game.

(I'd agree that the "label music_room_loop:" line probably shouldn't have any spaces at the beginning before 'label', as well.)


It looks like you're using the code from the music room cookbook recipe - pay careful attention to the indentation in the cookbook recipe, because indentation is very important in Ren'Py.
Server error: user 'Jake' not found

HigurashiKira
Miko-Class Veteran
Posts: 832
Joined: Mon Nov 01, 2010 9:10 pm
Contact:

Re: Help with Music Room

#6 Post by HigurashiKira »

Ok, adding the initp python code worked, thanks everyone!
I have moved to a new account. Please contact me here from now on. T/Y~

Post Reply

Who is online

Users browsing this forum: No registered users