Main Menu
  • Welcome to The RPG Maker Resource Kit.

Flesh of a Radio

Started by Tsunokiette, February 21, 2007, 12:53:27 AM

0 Members and 1 Guest are viewing this topic.

Tsunokiette

Lol at topic name.

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

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. :
$jukebox = Jukebox.new


EDIT : Fixed error pointed out by Zeriab. :)
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

:)

OMG OWNAGE! this is pure sweetness, thanks I am going to use this in an upcomming game of mine.  ;D
Watch out for: HaloOfTheSun

bulls84

#2
This is cool, I tried to make a jukebox out of events before.

Tsunokiette

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.
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

:)

Can someone move this to script database...I tried looking for it and it wasn't there. =[
Watch out for: HaloOfTheSun

Nightwolf

TSUNOKIETTE THIS SCRIPT ROCKS!
and stone and pebbles too!
Arlen is hot.

Ruhani777

you could make an event with a juke box, but im sure the script version is way better.

SexualBubblegumX


Zeriab

Good idea Tsu, I like it.

There is just one thing. Is this part just supposed to remove the extensions?
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:
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!

Tsunokiette

I only did the files that RPGMXP supports.

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

For example -

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

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

And thanks for the feedback! :D
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

Zeriab

Then try naming the file this: "Somemid.mid" or perhaps this: "filename.mid.mid"

Polraudio

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?

Kokowam

Nah, I think it's random, but it supports any file that you import (er, at least the ones stated).

Zeriab

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 ^_^

Zeriab

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.

DarkLordX

My apologies - I figured it could be limited somehow, at least keeping it to one event chain rather than two. ;/

Tsunokiette

Quote from: 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 ^_^


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.
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

Kokowam

I see.... Kind of. Zurgh. This script is too complex for me too understand. Go noob-ish scripting skills. @_@

Zeriab

@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

Kokowam

Quote from: 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 ^_^
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

PhoenixFire

*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]
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

[/spoiler]

Screenshot of error:

http://www.tiikoni.com/tis/view/?id=1164d7f


atassovi