Flesh of a Radio

I have to laugh at the topic name.

I haven't done any scripting for a while now. It has nothing to do with school, I just haven't felt like it and have gotten rusty. Who knows what the future will hold.

Anyways, on to the script. A long while ago (about a month or two after I stopped scripting) I was inspired to do this. It's a simple bit of script, and may not even be needed, but I wanted to let people know I was still alive :nya:

Script -

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
Expand to see the code.


This 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 do $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
Expand to see the code.



If you use this credit is due to Zeriab and myself. Original script by me, and Zeriab pointed out an error I myself would never have noticed. XD
Sounds like a good idea! I may try it sometime
This would have been handy when I made my own Jukebox script for a request. Ah, well. Thanks to you I have an understanding of Dir now. Cool.
Demo Please?
I still don't quite grasp how to use this...
@Ninjitsu500:
[QUOTE=Tsunokiette;321628]This is the flesh of a Radio/Jukebox.

All you need to do is script the bone.[/QUOTE]

Don't expect a demo ;)
I think there was a french script for including a jukebox in a project...
This is a pretty nice script, is it possible to set it up so that it will ADD songs through specific events?
Like, an event that calls the script to add a song to the radio's library?
I get a syntax error for this:
    def find(song)
    [COLOR=Red]=>[/COLOR] @list.each.do(|i| return i.index if i == song)
    end
Expand to see the code.
[QUOTE=Tdata;323691]I get a syntax error for this:[/QUOTE]

    def find(song)
     @list.each.do {|i| return i.index if i == song}
    end
Expand to see the code.
I don't see anything wrong with the syntax of that line. Unless it's the "space" between "do" and "{"... other than that it looks fine to me.

@zzzDude - Yes that is possible. Though that's something that would have to be done seperately. This is just the framework for a jukebox. A simple event script combination using switches should do perfectly.
@tsu: Look close at your code. You have parenthesis instead of brackets
    def find(song)
        @list.each.do(|i| return i.index if i == song)
    end
Expand to see the code.
Been working on this, it's good and fun =D

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=32591