Music Room script

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
Kadius Dar
Newbie
Posts: 22
Joined: Fri Jan 16, 2009 12:20 pm
Projects: Paths of Destiny, Viral-Day: The Beginning
Contact:

Music Room script

#1 Post by Kadius Dar » Sun Jan 18, 2009 8:46 pm

Using the music room script that TomPy has on the cookbook, I've seem to run into a few snags.

1. Right clicking is disabled in game, keeping the player from being able to access the save and load features that would be needed (if game is long enough) to save and load during the game. However this only happens when the game is started as stated in the next issue.

2. When clicking to exit the music room, it goes directly to the start of the game, instead of returning to the menu... this one has me completely confused.

I've placed the code at the base of the script to see if that would solve the problem with starting at the game instead of the menu, but it did not.

Here's the code that I have in my scripts:

Code: Select all

    #########################Music Room#########################
init python:

    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 mroom

    python:
        _game_menu_screen = None

        # The default track of music.
        playing = "walkmypath.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.vbox(xalign=0.5, ypos=100)
        music_button("Walking My Path", "walkmypath.mp3")
        music_button("A New Beginning", "newbeginning.mp3")
        music_button("Lonesome Nights", "lonesomenights.mp3")
        music_button("Lonesome Nights Revised", "lonesomenightsrevised.mp3")
        music_button("Morning Stroll", "morningstroll.mp3")
        music_button("Afternoon Love", "afternoonlove.mp3")
        ui.close()

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

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

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Music Room script

#2 Post by JQuartz » Sun Jan 18, 2009 9:48 pm

I don't if this method has any side effects but it seems to solve your problem:

Code: Select all

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.vbox(xalign=0.5, ypos=100)
        music_button("Walking My Path", "walkmypath.mp3")
        music_button("A New Beginning", "newbeginning.mp3")
        music_button("Lonesome Nights", "lonesomenights.mp3")
        music_button("Lonesome Nights Revised", "lonesomenightsrevised.mp3")
        music_button("Morning Stroll", "morningstroll.mp3")
        music_button("Afternoon Love", "afternoonlove.mp3")
        ui.close()

        # This is how we return to the main menu.
        ui.textbutton(
            "Return",
## Here's the change I've made to the script.
            clicked=ui.callsinnewcontext("_game_menu_save"),
            xalign=0.5,
            ypos=450,
            size_group="music")

    if ui.interact():
        jump music_room_loop
    else:
        return
I think the author of this code intended this to be called and not be jumped to.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Music Room script

#3 Post by PyTom » Sun Jan 18, 2009 10:05 pm

JQuartz, I don't see why a call in a new context will fix anything. It will likely cause more problems.

Kadius, what's likely happening is that something is falling into the music room, like a return was left out somewhere. Can you post a full script that exhibits the problem? I just ran the code I posted, and it works for me. So it's probably something to do with how this code is called.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Music Room script

#4 Post by JQuartz » Sun Jan 18, 2009 10:29 pm

PyTom wrote:JQuartz, I don't see why a call in a new context will fix anything. It will likely cause more problems.
Well it did result in exiting into the game menu. I think the problem is the music room was not called but jump to so when the return button was clicked, the resulting return causes the game to end.

On another matter, if Kadius you decides to try the code I have given, take note that it should only replace the original music_room_loop not stand alone. On the other hand maybe you should just call it.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Kadius Dar
Newbie
Posts: 22
Joined: Fri Jan 16, 2009 12:20 pm
Projects: Paths of Destiny, Viral-Day: The Beginning
Contact:

Re: Music Room script

#5 Post by Kadius Dar » Sun Jan 18, 2009 11:21 pm

The code starts off right after the first init block and image calls, which have no returns. Scanning through this myself, I didn't notice where a return had been missed, but I could have overlooked it.

The end of this marks the beginning of the code I posted above.

If the music room script should be a seperate script, then I'm at a loss, as I don't know how to call other scripts, just yet.

Code: Select all

label splashscreen:
    $ renpy.pause(0)
    scene black
    with Pause(0.5)

    show splash
    with dissolve
    with Pause(2.0)

    scene black
    with dissolve
    with Pause(1.0)

    return

# The game starts here.
label start:

label lovepoint:
    $ kaylalove = 0
    $ mitsunelove = 0
    $ ashleylove = 0

    scene kiss
    play music "lonesomenightsrevised.mp3"
    
    $ renpy.pause()
    
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    
    scene black
    show k1
    with dissolve
    
    "meh"    
    
    scene black
    show k2
    with dissolve
    
    "meh"
    
    scene black
    show k3
    with dissolve
    
    "meh"
    
    scene black
    show k4
    with dissolve
    
    "meh"
    
    scene black
    show k5
    with dissolve
    
    "meh"
    
    $ renpy.pause()
    scene black

menu:
    k "meh":
        t "Yeah..."
        $ kaylalove += 1
        jump kgr1
    "...":
        t "..."
        $ kaylalove -= 1
        jump kbr1
    
label kgr1:
    scene cafe
    show kmad
    with dissolve
    k "meh"
    k "meh"
    k "meh"
    jump cont1
    
label kbr1:
    scene cafe
    show kpoint
    with dissolve
    k "meh"
    k "meh"
    
menu:
    "Wait!":
        t "Wait!"    
        $ kaylalove += 0
        jump kgr2
    "I can do without you!":
        t "I can do without you!"
        $ kaylalove -= 1
        jump kbr2
label kgr2:
    scene cafe
    show kwait
    with dissolve
    k "Meh"
    return
    
label kbr2:
    scene cafe
    show kgive
    with dissolve
    k "Meh"
    return

label cont1:
    if kaylalove >= 1:
        jump GEnd
    else:
        jump BEnd
    
label BadEnd:
    if kaylalove <= -1:
        jump WEnd
    else:
        "meh"
    return
   
label GEnd:
    "meh"
    return
    
label WEnd:
    "meh"
    

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Music Room script

#6 Post by PyTom » Mon Jan 19, 2009 12:44 am

Ren'Py loads all files with a .rpy extension.

I don't see the problem with this script offhand. Could you post everything you have, including the init code and the music room code?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Kadius Dar
Newbie
Posts: 22
Joined: Fri Jan 16, 2009 12:20 pm
Projects: Paths of Destiny, Viral-Day: The Beginning
Contact:

Re: Music Room script

#7 Post by Kadius Dar » Mon Jan 19, 2009 12:52 am

I did notice, however, that when it enters the game when I try to leave the music room, it returns me to the music room once I've done a loop through the game. Then, when I click return in the music room, it returns me to the main menu.

Main script, with images and dialouge

Code: Select all

init:
    # Declare images below this line, using the image statement.
    # eg. image eileen happy = "eileen_happy.png"
    image kiss = "kiss.jpg"
    image cafe = "cafe.jpg"
    image bedroom = "bedroom.jpg"    
    image black = "black.JPG"
    image k1 = "k1.png"
    image k2 = "k2.png"
    image k3 = "k3.png"
    image k4 = "k4.png"
    image k5 = "k5.png"
    image kmad = "kaylamad.png"
    image kwait = "kaylawaitanger.png"
    image kpoint = "kaylapointmad.png"
    image kgive = "kaylagiveup.png"
    image mroom = "mroom.jpg"
    image asmile = "asmile.png"
    image alean = "alean.png"
    
    # Declare characters used by this game.
    $ t = Character('Takeya', color="#c8ffc8")
    $ k = Character('Kayla', color="#009909")
    $ m = Character('Mitsune', color="#009909")
    $ a = Character('Ashley', color="#009909")
    $ d = Character('Drake', color="#009909")
    $ w = Character('Female Voice', color='#009909')

    image splash = "splash.png"

label splashscreen:
    $ renpy.pause(0)
    scene black
    with Pause(0.5)

    show splash
    with dissolve
    with Pause(2.0)

    scene black
    with dissolve
    with Pause(1.0)

    return

# The game starts here.
label start:

label lovepoint:
    $ kaylalove = 0
    $ mitsunelove = 0
    $ ashleylove = 0

    scene kiss
    play music "lonesomenightsrevised.mp3"
    
    $ renpy.pause()
    
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    "meh"
    
    scene black
    show k1
    with dissolve
    
    "meh"    
    
    scene black
    show k2
    with dissolve
    
    "meh"
    
    scene black
    show k3
    with dissolve
    
    "meh"
    
    scene black
    show k4
    with dissolve
    
    "meh"
    
    scene black
    show k5
    with dissolve
    
    "meh"
    
    $ renpy.pause()
    scene black

menu:
    k "meh"        
    "Yeah...":
        t "Yeah..."
        $ kaylalove += 1
        jump kgr1
    "...":
        t "..."
        $ kaylalove -= 1
        jump kbr1
    
label kgr1:
    scene cafe
    show kmad
    with dissolve
    k "meh"
    k "meh"
    k "meh"
    jump cont1
    
label kbr1:
    scene cafe
    show kpoint
    with dissolve
    k "meh"
    k "meh"
    
menu:
    "meh":
        t "meh"    
        $ kaylalove += 0
        jump kgr2
    "meh":
        t "meh"
        $ kaylalove -= 1
        jump kbr2
label kgr2:
    scene cafe
    show kwait
    with dissolve
    k "meh"
    return
    
label kbr2:
    scene cafe
    show kgive
    with dissolve
    k "meh"
    
    hide kgive
    with dissolve
    
    t "meh"
    "meh"
    w "meh"
    "meh"

    show asmile
    with dissolve
  
    a "meh"    
    
    
    
    #######################################Ending Possibilities############################################
label cont1:
    if kaylalove >= 1:
        jump GoodEnd
    else:
        jump BadEnd
    
label BadEnd:
    if kaylalove <= -1:
        jump WorstEnd
    else:
        "meh"
    return
   
label GoodEnd:
    "meh"
    return
    
label WorstEnd:
    "meh"
    
    #########################Music Room#########################
init python:

    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 mroom

    python:
        _game_menu_screen = None

        # The default track of music.
        playing = "walkmypath.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.vbox(xalign=0.5, ypos=100)
        music_button("Walking My Path", "walkmypath.mp3")
        music_button("A New Beginning", "newbeginning.mp3")
        music_button("Lonesome Nights", "lonesomenights.mp3")
        music_button("Lonesome Nights Revised", "lonesomenightsrevised.mp3")
        music_button("Morning Stroll", "morningstroll.mp3")
        music_button("Afternoon Love", "afternoonlove.mp3")
        ui.close()

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

    if ui.interact():
        jump music_room_loop
    else:
        return
Main menu script:

Code: Select all

label main_menu:
    $ ui.add(renpy.Keymap(toggle_fullscreen = renpy.toggle_fullscreen))
    $ ui.window(style='mm_root', background='menu.jpg')
    $ ui.button(clicked=ui.jumpsoutofcontext('start'), background='startgame.png',hover_background='startgameh.png',xpos=322,ypos=172,xminimum=220,yminimum=62 )
    $ ui.text('Start Game',hover_color='#0000',color='#0000',size=22,font='DejaVuSans.ttf')
    $ ui.button(clicked=_intra_jumps('load_screen', 'main_game_transition'), background='loadgame.png', hover_background='loadgameh.png', xpos=312, ypos=232,xminimum=260,yminimum=50)
    $ ui.text('Continue',hover_color='#0000',color='#0000',size=22,font='DejaVuSans.ttf')
    $ ui.button( clicked=_intra_jumps('preferences_screen','main_game_transition'), background='options.png', hover_background='optionsh.png', xpos=349, ypos=288,xminimum=170,yminimum=50)
    $ ui.text('Preferences',hover_color='#0000',color='#0000',size=22,font='DejaVuSans.ttf')
    $ ui.button( clicked=ui.jumps('_quit'), background='quit.png', hover_background='quith.png', xpos=382, ypos=390,xminimum=100,yminimum=41)
    $ ui.text('Quit',hover_color='#0000',color='#0000',size=22,font='DejaVuSans.ttf')
    $ ui.button( clicked=ui.jumps('music_room'), background='musicroom.png', hover_background='musicroomh.png', xpos=307, ypos=342,xminimum=220,yminimum=50)
    $ ui.text('Quit',hover_color='#0000',color='#0000',size=22,font='DejaVuSans.ttf')   
    $ ui.interact(suppress_overlay=True, suppress_underlay=True, mouse='mainmenu')
Would you like the options? I've only changed the background image and music playing for it, however.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Music Room script

#8 Post by PyTom » Mon Jan 19, 2009 2:41 am

The main menu runs in a menu context, so you should use ui.jumpsoutofcontext to access the music room.

You're missing a return after label WorstEnd, such that falling off the end of that would bring you into the music room.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Music Room script

#9 Post by JQuartz » Mon Jan 19, 2009 2:58 am

Looks like I got it wrong. Must have misread the question. Also if you are using the main menu generator, why make the words for the textbutton invisible (as in your case)? It would be better if you just toggle imagebutton. Also you don't need to copy and paste to create a new button. Just click on add new button.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Kadius Dar
Newbie
Posts: 22
Joined: Fri Jan 16, 2009 12:20 pm
Projects: Paths of Destiny, Viral-Day: The Beginning
Contact:

Re: Music Room script

#10 Post by Kadius Dar » Mon Jan 19, 2009 10:24 am

TomPy:
Thanks, you've been a great help in my learning to code properly!

JQuartz:
The reason I didn't use an imagemap or an imagebutton was mainly because my attempts at doing so were major failures. I'm still learning to code simple things, but on a side note, I can pretty much look at a script and am able to modify it to suit my needs. Which is what I did with your menu generated script. The reason for the text being invisible is the frame is used were actually images with an alpha that were the names I wanted to use, and the hover image was a slightly larger version of the same text. Still giving me the effect I wanted. I'll take other stabs at the imagemaps and buttons a little later on in my learning curve.

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Music Room script

#11 Post by JQuartz » Mon Jan 19, 2009 2:03 pm

Ignore my suggestions if you didn't use main menu generator. The learning curve for ui is quite tough (though still nowhere near python) so don't push yourself too much. The suggestions were made with the assumption you were using main menu generator cause with the main menu generator, all the thing suggested could be done easily.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Post Reply

Who is online

Users browsing this forum: No registered users