Random Music Generator

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Random Music Generator

#1 Post by Westeford »

Bare bones music generator with minimal user input.
You may copy the following code, or download the zip file for the full game including the sounds I used.
I encourage everyone to experiment and improve the code. I hope to be doing the same and uploading my own upgrades to this code.
Have fun!

UPDATE: 6/28/19
Thanks to Human Bolt Diary for the more efficient code. Now it's even simpler than I originally thought.

Code: Select all

# Music notes
define notes = [
    "images/a4.mp3",
    "images/a-4.mp3",
    "images/b4.mp3",
    "images/c4.mp3",
    "images/c-4.mp3",
    "images/d4.mp3",
    "images/d-4.mp3",
    "images/e4.mp3",
    "images/f4.mp3",
    "images/f-4.mp3",
    "images/g4.mp3",
    "images/g-4.mp3",
]

# The game starts here.
label start:
    $ count = 12 # How many notes will play before ending the program.

label rando_music:
    python:
        for x in range(count):
            pick = renpy.random.choice(notes)
            renpy.play(pick, channel='sound')
            renpy.pause(0.5)
    return
Just save this in your projects folder and extract the contents.
musicRando.zip
(807.37 KiB) Downloaded 76 times
Last edited by Westeford on Fri Jun 28, 2019 8:07 am, edited 3 times 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: Random Music Generator

#2 Post by Imperf3kt »

Could the choice statement be used for this?
https://www.renpy.org/doc/html/atl.html ... -statement
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

Human Bolt Diary
Regular
Posts: 111
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Random Music Generator

#3 Post by Human Bolt Diary »

No need for all those if statements:

Code: Select all

# Music notes
define notes = [
    "images/a4.mp3",
    "images/a-4.mp3",
    "images/b4.mp3",
    "images/c4.mp3",
    "images/c-4.mp3",
    "images/d4.mp3",
    "images/d-4.mp3",
    "images/e4.mp3",
    "images/f4.mp3",
    "images/f-4.mp3",
    "images/g4.mp3",
    "images/g-4.mp3",
]

# The game starts here.
label start:
    $ count = 12 # How many notes will play before ending the program.

label rando_music:
    python:
        for x in range(count):
            pick = renpy.random.choice(notes)
            renpy.play(pick, channel='sound')
            renpy.pause(0.5)
    return

User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Re: Random Music Generator

#4 Post by Westeford »

Human Bolt Diary wrote: Fri Jun 28, 2019 7:09 am No need for all those if statements:
Thanks. The code has now been updated.

Post Reply

Who is online

Users browsing this forum: No registered users