Forums Archived

The forums are being archived. See this topic for more information.

The .rb Files wont even Load!

Get help and support with Rubygame

Re: The .rb Files wont even Load!

Postby tyler » Wed Oct 28, 2009 12:32 am

This line here:

Code: Select all
bgmusic = Music.load("audio\bgmusic.mp3")


I didn't notice this last time, but you're using Music, which is part of the Rubygame module. So you have to change it to:

Code: Select all
bgmusic = Rubygame::Music.load("audio\bgmusic.mp3")


Or if you'd rather not type "Rubygame::" for each Rubygame class:

Code: Select all
require "rubygems"
require "rubygame"
include Rubygame
tyler
 
Posts: 25
Joined: Sat Feb 28, 2009 6:10 am

Re: The .rb Files wont even Load!

Postby jacius » Wed Oct 28, 2009 4:40 am

cavygalaxy wrote:i figured out the problem, but i still get an error saying that it cant find the file. supposedly, subdirectories are Not \, but /.

In Ruby (and many other programming languages), the \ (backslash) is used as an "escape character", meaning it combines with the next letter to mean something different. For example, "\n" means newline, "\t" means tab, and "\b" means backspace -- which is why it couldn't find the file, it thought the "\b" in your string meant a backspace, so it was looking for "audigmusic.mp3".

To have a literal \ in your string, you need to type \\, like this:

Code: Select all
bgmusic = Rubygame::Music.load("audio\\bgmusic.mp3")

However, I don't recommend using the backslash, because it won't work on Linux or Mac. One better way to do that is to use File.join. File.join uses "\\" or "/" depending on which is correct for the platform your game is running on.

Code: Select all
bgmusic = Rubygame::Music.load( File.join("audio","bgmusic.mp3") )

There is an even better way to do this, taking advantage of one of Rubygame's features, but it's more complex to explain, so I'm going to make a wiki article about it. I'll post again here when it's done.

Update: Here's the article so far, with code snippets: Autoloading Surfaces, Sounds, and Music
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Previous

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron