Day/Night Hub with music

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
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Day/Night Hub with music

#1 Post by lsf22 »

I'm trying to add music to my script that has a Day/Night cycle to a main hub that has music playing in the background, but not in order but a shuffle/Random play function instead. I've tried testing out the code from the music room as an example but that doesn't even work as a code set to test and learn from. I'm new to Renpy so what solutions and alternatives would I have?



As for this code from the online documentation does this work for the music channel or other channels as well

Code: Select all

define audio.sunflower = "music/sun-flower-slow-jam.ogg"
Last edited by lsf22 on Fri Mar 04, 2022 8:09 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Day/Night Hub with music

#2 Post by Ocelot »

lsf22 wrote: Thu Mar 03, 2022 11:22 pm Im trying to add music to my script that has a Day/Night cycle to a main hub that has music playing in the background but not in order but a shuffle/Random play function. I've tried testing out the code from the music room as an example but that doesn't even work as a code set to test and learn from. I'm new to Renpy so what solutions and alternatives would I have?
This code will shuffle order of songs and play them.

Code: Select all

define audio.snap = "audio/ch1_FingerSnap.wav"
define audio.broken_clock = "audio/Clock_Stop.wav"
define audio.angela = "audio/ch8_kether_ep1_malkuth1.wav"
define audio.shot = "audio/Assassination.wav"
define audio.awakening = "audio/BossBird_Birth.wav"

label start_music:
    python:
        playlist = [audio.snap, audio.broken_clock, audio.angela, audio.shot, audio.awakening]
        renpy.random.shuffle(playlist)
    play music playlist
    return

label start:
    call start_music
    "You can hear music, playing in randomised order, looping"
    call start_music
    "Music order was re-shuffled"
    return
lsf22 wrote: Thu Mar 03, 2022 11:22 pm As for this code from the online documentation does this for the music channel or other channels as well

Code: Select all

define audio.sunflower = "music/sun-flower-slow-jam.ogg"
It defines a name in audio namespace. Channels have no relation to that, they only matter when playing something.
< < insert Rick Cook quote here > >

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Day/Night Hub with music

#3 Post by lsf22 »

Does it need the call start_music code twice?

Code: Select all

abel start:
    call start_music
    "You can hear music, playing in randomised order, looping"
    call start_music
    "Music order was re-shuffled"
    return

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Day/Night Hub with music

#4 Post by Ocelot »

No. It just there to show that you can call it again. If you want, you can place music code directly in script, insead of calling another label.
< < insert Rick Cook quote here > >

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Day/Night Hub with music

#5 Post by lsf22 »

Thanks, I was able to edit it so it calls a random music track in the background. I made some changes to it so that it's part of a room based hub that has a Day/Night time cycle.
I had it at first in the Day cycle but since the the day/night cycle is short and so are the activities it ends up playing a another song way before you can enjoy more than 30 seconds of a song.

I ended up making some changes so that the Room hub with Day/Night time cycle has a image button that shows in the hubs corner so that you can activate the music, play it randomly as needed and the bonus is that you are now able to hear the song in it's entirety.

The only problem is that now the button is that you end up advancing the time when you decide to click the button when you either activate the music or want to play a random song. It ends up selecting a choice from the list choices from some reason.

Day/Night room hub script:

Code: Select all

#A room hub script with a Day and Night time cycle

#Stats for the character to gain from activities
default strength = 0
default intelligence = 0
default charm = 0
default money = 0

label Daytime:

    scene bg_blue

    menu:
        "It's currently daytime, what do you want to do?"

        "Workout":
             "You worked out during the day"
             $ strength +=1
             jump Nighttime

        "Work":
            "You went to work"
            $ money +=10
            jump Nighttime


label Nighttime:

    scene bg_blue

    menu:
        "It's currently nighttime, What do you want to do?"

        "Study":
             "You studied all night"
             $ intelligence +=1
             jump Daytime

        "Play Music":
             "You decided to play music"
             $ charm +=1

        "Sleep":
            "You decided to go to sleep"
            jump Daytime
music button script

Code: Select all

# Music button screen
screen music_button:

    imagebutton: #the image button to play music and call start_music
        idle "button.png"
        xanchor 0.0
        yanchor 0.0
        xpos 100
        ypos 100
        action Call("start_music")
Music with random play script code:

Code: Select all

#music script that plays music from a list at random
define audio.track1 = "audio/track1.ogg"
define audio.track2 = "audio/track2.ogg"
define audio.track3 = "audio/track3.ogg"
define audio.track4 = "audio/track4.ogg"


label start_music:
    python:
        playlist = [audio.track1, audio.track2, audio.track3, audio.track4]
        renpy.random.shuffle(playlist)
    play music playlist
    return
Is there a statement that I can use for start_music so that it does not result in the game advancing on it's own? I notice with how the code is now it selects the last choice options, if it's day it will select "work", if it's night it will select "sleep".

Also if anyone wants to copy and use the code they can. This one is just a simple one for demonstration and practice
Attachments
Screenshot of the day cycle of a room hub
Screenshot of the day cycle of a room hub

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2437
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Day/Night Hub with music

#6 Post by Ocelot »

Yeah, jumping away from within choice menu is not the best idea. You can change label into Python function and use Function action to call it:

Code: Select all

init python:
    def start_music(playlist ):
        renpy.random.shuffle(playlist)
        renpy.music.play(playlist, loop=True)

# Notice, that I moved list of tracks outside of function, so you can provide different lists in different places
button action Function(start_music, [audio.track1, audio.track2, audio.track3, audio.track4])
< < insert Rick Cook quote here > >

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Day/Night Hub with music

#7 Post by lsf22 »

Thanks Ocelot, this works very well.

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Day/Night Hub with music

#8 Post by lsf22 »

I have a new question. Can I be able to view what bgm is currently playing. Last time I tried to place the output in a [ ], it gave me some weird output and not the track number or anything.

Question 2. To create a Next, as in next track function. Do I need to create it as a Creator-Defined Statements (CDS)?
Attachments
After using [start_music] it gave me this output instead of a bgm track number
After using [start_music] it gave me this output instead of a bgm track number

Post Reply

Who is online

Users browsing this forum: Dark79, Qchosis