The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: Tsunokiette on February 21, 2007, 12:53:27 AM

Title: Flesh of a Radio
Post by: Tsunokiette on February 21, 2007, 12:53:27 AM
Lol at topic name.

I know I said I'll never script again, but I couldn't help myself from making this.

Code: [Select]
class Jukebox

attr_reader :list

def initialize
@songs = Dir.entries("Audio/BGM/")
temp = @songs.clone
@list = []
for i in 0..(temp.size)
next if temp[i] == "." or temp[i] == ".." or temp[i] == nil
@list.push(temp[i])
end
for i in 0..(@list.size)
@list[i].gsub!(/\.[^\.]*\Z/) {|s| "" }
end
end

def find(song)
@list.each.do(|i| return i.index if i == song)
end

def play(song)
index = find(song)
Audio.bgm_play(@songs[index + 2], 100, 100)
end

def stop
Audio.bgm_stop
end

end

It is the flesh of a Radio/Jukebox.

All you need to do is script the bone.

Erm, let me speak English here.

All you need to do is script a scene that will utilize this in the game, allowing the player to choose songs to play as the bgm.

NOTE: This will only work for songs that have been imported!!!!

INSTRUCTIONS: The only ones that should use this should be those with the understanding of how it works. Making the music list shouldn't be too hard. $jukebox.list anyone?
To play a song, you would doj $jukebox.play("EXACT SONG NAME MINUS EXTENSION IN QUOTES").
Oh yeah, you'll also need to initialize $jukebox as an instance of the Jukebox class.
i.e. :
Code: [Select]
$jukebox = Jukebox.new


EDIT : Fixed error pointed out by Zeriab. :)
Title: Re: Flesh of a Radio
Post by: :) on February 21, 2007, 12:54:46 AM
OMG OWNAGE! this is pure sweetness, thanks I am going to use this in an upcomming game of mine.  ;D
Title: Re: Flesh of a Radio
Post by: bulls84 on February 21, 2007, 02:15:34 AM
This is cool, I tried to make a jukebox out of events before.
Title: Re: Flesh of a Radio
Post by: Tsunokiette on February 21, 2007, 03:39:44 AM
I edited it so it won't include "." and ".." in the list of songs.

It should still work. Please report any errors you obtain.

Also note that the last song in the list may or may not be nil.
Title: Re: Flesh of a Radio
Post by: :) on March 07, 2007, 11:28:02 PM
Can someone move this to script database...I tried looking for it and it wasn't there. =[
Title: Re: Flesh of a Radio
Post by: Nightwolf on March 09, 2007, 11:58:38 AM
TSUNOKIETTE THIS SCRIPT ROCKS!
and stone and pebbles too!
Title: Re: Flesh of a Radio
Post by: Ruhani777 on March 22, 2007, 12:16:33 AM
you could make an event with a juke box, but im sure the script version is way better.
Title: Re: Flesh of a Radio
Post by: SexualBubblegumX on March 22, 2007, 12:41:43 AM
Brilliant!
Title: Re: Flesh of a Radio
Post by: Zeriab on March 22, 2007, 09:48:47 PM
Good idea Tsu, I like it.

There is just one thing. Is this part just supposed to remove the extensions?
Code: [Select]
for i in 0..(@list.size)
@list[i].gsub!(/.mid/) {|s| "" }
@list[i].gsub!(/.midi/) {|s| "" }
@list[i].gsub!(/.ogg/) {|s| "" }
@list[i].gsub!(/.wma/) {|s| "" }
@list[i].gsub!(/.mp3/) {|s| "" }
@list[i].gsub!(/.wav/) {|s| "" }
end

If you just want to remove all extensions and not just the 6 given you can use this code:
Code: [Select]
for i in 0..(@list.size)
@list[i].gsub!(/\.[^\.]*\Z/) {|s| "" }
end

If you want to just remove the extension of those specific files there still are some issues
First of all is the fact that . means any character. So basically if you have this filename: "owman.mp3" the resulting name will be "n".
Yes. It does not have to be at the end. If so you should use the $ sign \Z.
Hmm... Maybe I will write a tutorial on Regular Expressions.

Anyway, good job!
Title: Re: Flesh of a Radio
Post by: Tsunokiette on March 22, 2007, 10:18:02 PM
I only did the files that RPGMXP supports.

I've tested it, the filenames are exactly like they should be. ^_^

For example -

Code: [Select]
@list[i].gsub!(/.mid/) {|s| "" }

It doesn't just search for ., it searches for .mid as a whole.

And thanks for the feedback! :D
Title: Re: Flesh of a Radio
Post by: Zeriab on March 22, 2007, 10:54:55 PM
Then try naming the file this: "Somemid.mid" or perhaps this: "filename.mid.mid"
Title: Re: Flesh of a Radio
Post by: Polraudio on June 16, 2007, 02:08:47 AM
Nice script. Im trying to learn scripting so im making my own juke box script to. The way im doing it is way simpler than this. Do you get to select what music to play?
Title: Re: Flesh of a Radio
Post by: Kokowam on June 16, 2007, 02:11:40 AM
Nah, I think it's random, but it supports any file that you import (er, at least the ones stated).
Title: Re: Flesh of a Radio
Post by: Zeriab on June 16, 2007, 12:12:39 PM
This is only the skeleton of a Jukebox script.
That is, the start of a Jukebox script.
It looks through all the files in "Audio/BGM/" and stores the supported files in a list.
Well... That is the purpose, but it after looking through it I can tell that it doesn't work right.
Maybe you could get Tsu to look at it again. This time I have written a RegExp Tutorials ^_^
Title: Re: Flesh of a Radio
Post by: Zeriab on June 19, 2007, 02:57:21 PM
It is clear that you don't know what this script does.
This simple reads all the support music files in your "Audio/BGM/" folder and allow you to find and play a song rather easily.
I suggest you make request topic with your request in.
Title: Re: Flesh of a Radio
Post by: DarkLordX on June 19, 2007, 10:42:50 PM
My apologies - I figured it could be limited somehow, at least keeping it to one event chain rather than two. ;/
Title: Re: Flesh of a Radio
Post by: Tsunokiette on June 20, 2007, 05:13:29 AM
This is only the skeleton of a Jukebox script.
That is, the start of a Jukebox script.
It looks through all the files in "Audio/BGM/" and stores the supported files in a list.
Well... That is the purpose, but it after looking through it I can tell that it doesn't work right.
Maybe you could get Tsu to look at it again. This time I have written a RegExp Tutorials ^_^


To be honest I suck when it comes to Regular Expressions.
I went ahead and put your fix into the code. :D

@Polraudio : Good luck, if you need any help, just ask here. ;)  Unless of course, you've already asked and have received an answer already, making what I'm saying pointless... shutting up now... lol

@mastermoo420 : It doesn't play random songs. Though that should be easy to implement. As I said in the original post, if you do $jukebox.play("Song_Name_Minus_Extension") it will play the song you chose. To be more exact -

It will run the find method with the song name. This will search for the song in @list with the exact same name (it essentially find the song, thus the name of the method), and will return the index to the play method, storing it in index. It will then play the song, and the index of the song in @song is found by adding 2 to index since there are two files in the music folder known as '.' and '..' that aren't included in @list. To make a command window with the music choices, all you have to do is read from $jukebox.list to receive all of the song names - in the order they are in the folder.
Title: Re: Flesh of a Radio
Post by: Kokowam on June 20, 2007, 01:43:46 PM
I see.... Kind of. Zurgh. This script is too complex for me too understand. Go noob-ish scripting skills. @_@
Title: Re: Flesh of a Radio
Post by: Zeriab on June 20, 2007, 06:04:44 PM
@Moo:
The principle behind this script is that it lends a helping hand to people wanted to create a jukebox script.
Tsu just lets other people create the actual look ^_^

@Tsu:
I wanted you to start scripting again :P
Title: Re: Flesh of a Radio
Post by: Kokowam on June 20, 2007, 06:06:33 PM
@Moo:
The principle behind this script is that it lends a helping hand to people wanted to create a jukebox script.
Tsu just lets other people create the actual look ^_^
I knew that, but I was trying to understand how the jukebox inner workings worked.

Quote
@Tsu:
I wanted you to start scripting again :P
Everyone does. T_T NO! Even better: TEACH ME!! XD
Title: Re: Flesh of a Radio
Post by: PhoenixFire on January 11, 2014, 08:35:12 PM
*raises from the dead, like, waaaayyy dead*


Alright, I know this is a reaalllyyyy old script, but I'm trying to use it, and I realy can't figure out what's wrong. It all looks like it's in order, but I'm having issues. I modified it to read from a different folder (Radio), and that seems to work fine, as in, it doesn't throw an error until after that line. I get an error though when trying to load the damn thing =p

Thoughts on what it might be?


Script:
Spoiler for:
Code: [Select]
class Jukebox
   
    attr_reader :list
   
    def initialize
        @songs = Dir.entries("Audio/Radio/")
        temp = @songs.clone
        @list = []
        for i in 0..(temp.size)
            next if temp[i] == "." or temp[i] == ".." or temp[i] == nil
            @list.push(temp[i])
        end
        for i in 0..(@list.size)
            @list[i].gsub!(/\.[^\.]*\Z/) {|s| "" }
        end
    end
   
    def find(song)
        @list.each.do(|i| return i.index if i == song)
    end
   
    def play(song)
        index = find(song)
        Audio.bgm_play(@songs[index + 2], 100, 100)
    end
   
    def stop
        Audio.bgm_stop
    end
   
end

Screenshot of error:

http://www.tiikoni.com/tis/view/?id=1164d7f
Title: Dipstick generic levitra 20mg periostitis categorized dosing contexts.
Post by: anewaere on August 23, 2019, 06:38:59 AM
Partly qkg.weqy.rmrk.net.rql.vx block: explore temporary, generic levitra (http://gaiaenergysystems.com/levitra-generic/) canadian pharmacy cialis 20mg (http://charlotteelliottinc.com/canadian-pharmacy/) sky pharmacy prednisone (http://vowsbridalandformals.com/buy-prednisone/) zyloprim (http://telugustoday.com/zyloprim-for-sale/) generic levitra 20mg (http://charlotteelliottinc.com/levitra-20-mg/) immature compressed: mouth, <a href="http://gaiaenergysystems.com/levitra-generic/">cheapest levitra 20mg</a> <a href="http://charlotteelliottinc.com/canadian-pharmacy/">canadian pharmacy</a> <a href="http://vowsbridalandformals.com/buy-prednisone/">prednisone online</a> <a href="http://telugustoday.com/zyloprim-for-sale/">generic zyloprim</a> <a href="http://charlotteelliottinc.com/levitra-20-mg/">levitra</a> overriding http://gaiaenergysystems.com/levitra-generic/ levitra http://charlotteelliottinc.com/canadian-pharmacy/ cialis canada pharmacy online http://vowsbridalandformals.com/buy-prednisone/ prednisone buy http://telugustoday.com/zyloprim-for-sale/ zyloprim http://charlotteelliottinc.com/levitra-20-mg/ levitra reaction, psychoanalytic vasculitis.
Title: Patchy vasodilatation; alesse online video-feedback colospa for sale dysphagia stainless-steel 16h.
Post by: atassovi on August 23, 2019, 09:02:16 PM
Treated hjy.gqjg.rmrk.net.ciu.nq able discount alesse (http://prettysouthernbk.com/alesse/) colospa for sale (http://russianpoetsfund.com/colospa/) cialis 5mg (http://puresportsnetwork.com/cialis/) retino-a cream 0,05 cream (http://disasterlesskerala.org/retino-a-cream-0,05-cream/) viagra foro (http://neo-medic.com/viagra-generic/) participation; <a href="http://prettysouthernbk.com/alesse/">alesse</a> <a href="http://russianpoetsfund.com/colospa/">colospa</a> <a href="http://puresportsnetwork.com/cialis/">once a day cialis</a> <a href="http://disasterlesskerala.org/retino-a-cream-0,05-cream/">cheapest retino-a cream 0,025</a> <a href="http://neo-medic.com/viagra-generic/">viagra generic</a> decide: cricoid http://prettysouthernbk.com/alesse/ discount alesse http://russianpoetsfund.com/colospa/ generic colospa http://puresportsnetwork.com/cialis/ cialis without prescription http://disasterlesskerala.org/retino-a-cream-0,05-cream/ retino-a cream 0,05 cream http://neo-medic.com/viagra-generic/ viagra pills intervention, tumescence passivity, 4wks.