Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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 -

Code:
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

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


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
 

OS

Sponsor

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.
 
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?
 

Tdata

Sponsor

I get a syntax error for this:
Code:
    def find(song)
    [COLOR=Red]=>[/COLOR] @list.each.do(|i| return i.index if i == song)
    end
 
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.
 

Zeriab

Sponsor

@tsu: Look close at your code. You have parenthesis instead of brackets
Code:
    def find(song)
        @list.each.do(|i| return i.index if i == song)
    end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top