[RMXP]Radio/Jukebox script issue

Started by PhoenixFire, January 11, 2014, 03:29:53 pm

Previous topic - Next topic

PhoenixFire

January 11, 2014, 03:29:53 pm Last Edit: January 11, 2014, 04:44:43 pm by DigitalSoul
   So I'm trying to use this barebones script to get and play music. I modified it to read from a different folder (Radio), and that seems to work fine. I get an error though when trying to load the damn thing =p

Thoughts on what it might be?


Script:
Spoiler: ShowHide


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



Screenshot of error:
http://www.tiikoni.com/tis/view/?id=1164d7f
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

Wizered67

Someone else is welcome to correct me if I'm wrong on this, but I believe that on the line
@list.each.do(|i| return i.index if i == song)
the parentheses should be curly braces {}.

Here's the corrected line:
@list.each.do{|i| return i.index if i == song}

PhoenixFire

That fixed one problem, now I have this. I've narrowed it down to it happening when I initialize it..

http://www.tiikoni.com/tis/view/?id=5020c9a


I'll upload a working copy of it if needed..
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

ForeverZer0

In the "intitialize" method, instead of creating copies and enumerating multiple times, just create the array of song names in one command.

@songs = Dir.glob("Audio/BGM/*.{ogg,mp3,wma,mid,wav}")


Not only is it more efficient, but also allows you to determine which formats are accepted, so if someone drops some file in another format in there, it won't crash the game, but simply be ignored.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.