The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: wizaerd on June 14, 2008, 02:55:04 PM

Title: Filenames with spaces
Post by: wizaerd on June 14, 2008, 02:55:04 PM
Am I correct in assuming RMXP doesn't work well with filenames with spaces?  Fir example, FileText.exist?() is returning false to me on a file I know for a fact exists, and RPG::Cache.picture() is also generating an error with that same file.  Is there anyway to get it to recognize a filename with a space in it?
Title: Re: Filenames with spaces
Post by: Falcon on June 14, 2008, 03:00:36 PM
Couldn't you just remove the space?

There is a way though, check the Scene_Save and Load methods until you find how it reads the save files, I believe the save files have a space in them, so just look through those methods and you'll find it.
Title: Re: Filenames with spaces
Post by: wizaerd on June 14, 2008, 03:11:43 PM
Unfortunately, for what I'm attempting, no I cannot remove the space... But either way, I'll look into the save system...

thanx


[EDIT]
Unfortunately, nothing helpful in the save and load game scripts...  They use FileTest.exist?() as well, so I assume a save game with a space in it would fail too...
Title: Re: Filenames with spaces
Post by: Falcon on June 14, 2008, 06:17:43 PM
Search around ruby websites, you just need to find the encoding for a space, I think its %20 or something like that, but I don't know for sure, so just search around.
Title: Re: Filenames with spaces
Post by: ahref on June 14, 2008, 10:32:44 PM
i try to convice people everday that spaces cause problems :(. i spend about 2 hours every few months fixing friends IT school work. :(

just out of intrest why cant you remove the space ?
Title: Re: Filenames with spaces
Post by: wizaerd on June 15, 2008, 07:41:16 PM
Because the script I was writing at the time was relying upon the character's name to look for an associated image file.  The character's name at the time was made up of two names, so it wouldn't work.  But I worked around it with a bit of a kludge.

In this day and age, filenames with spaces in themare quite common, and don't (or shouldn't) cause the problems they did 5 or even 10 years ago.  I work as a professional software developer (C#), and always take into consideration that filenames may have space in them.
Title: Re: Filenames with spaces
Post by: ahref on June 15, 2008, 09:20:30 PM


String firstName = "Fred";
  String lastName  = "Flinstone";
  String fullName  = firstName + lastName;
  file = fullName + ".png"


...
Title: Re: Filenames with spaces
Post by: wizaerd on June 16, 2008, 03:37:31 AM
Quote from: anchovy on June 15, 2008, 09:20:30 PM


String firstName = "Fred";
  String lastName  = "Flinstone";
  String fullName  = firstName + lastName;
  file = fullName + ".png"


...

Nope, wouldn't have worked.  But as I said, it's a moot point, I already resolved it...  But thanx
Title: Re: Filenames with spaces
Post by: Zeriab on June 16, 2008, 05:08:57 AM
If it's only because of the name having spaces you could just replace the spaces with something else like _
Here is an example of text substitution:

name =  "Fred Flintstone"
new_name = name.gsub(/ /, '_')



Now I see you have resolved it.
Could you share your solution? You know, in case someone else comes into the same situation.

*hugs*
- Zeriab
Title: Re: Filenames with spaces
Post by: ahref on June 16, 2008, 06:34:44 AM
:D that would also work.
Title: Re: Filenames with spaces
Post by: wizaerd on June 16, 2008, 03:17:53 PM
Quote from: Mola Mola on June 16, 2008, 05:08:57 AM
If it's only because of the name having spaces you could just replace the spaces with something else like _
Here is an example of text substitution:

name =  "Fred Flintstone"
new_name = name.gsub(/ /, '_')



Now I see you have resolved it.
Could you share your solution? You know, in case someone else comes into the same situation.

*hugs*
- Zeriab

Yup, the string replacement was the answer. So now in my script I pull the name of the actor as usual, but automatically do a string replacement on the chance there's a space in it.  This way there's no hard coded image names and works for any actor/character.