I'm moving all of my scripts from rmxp.org to this site. I like it here better.IntroductionIf you are using Vista, you have probably already learned by now that unless you are logged in with administrator permissions, you cannot write or update data in the Programs Files directory. Any user who installs their RPG Maker XP game in this directory will not be able to save their games or update their game option files.
So what are we to do, eh? Yes, Vista is new, and it's a real pain in the arse, but like it or not, it's not going to go away. Best to prepare for the future, I say.
Let the fun begin!
Step 1: Create Game Directory On StartupThe first time that your user runs your game, a directory needs to be created for them that is local to their account. We will use this directory for our save files and any other files that needs to be modified by players.
The following code gets a path to a user's directory. Then it creates a directory for your game. The directory is only created the first time that the user plays the game.
The directory
must be local to the user's machine. (which is why I have used the WinAPI below).
1. Open the script editor for your project and go to
Main.
2. Add the following code under
begin:
CODE
# Get Your Path (WinAPI)
SHGetFolderPath = Win32API.new("shell32.dll","SHGetFolderPath",["P","I","P","I","P"],"I")
path = " " * 256
SHGetFolderPath.call(0,0x0023,0,0,path)
# Define Your Game Folder (use global variables)
$appPath = path.strip.gsub("\000","") + "\\Game Name"
# Replace backslashes with forward slashes
$appPath = $appPath.gsub(/\\/, "/")
# Create Your Folders
if !File.exists?($appPath)
Dir.mkdir($appPath)
end
Note: Notice the reference to 0x0023? This is a constant that points to the user's Application Data directory. On Windows XP, this constant points to this directory:
C:\Documents and Settings\All Users\Application Data. The value for this constant changes, depending upon the operating system. This means that there is no need to hard-code anything! If you would like a full list of constants, go here:
http://rubyforge.org/pipermail/win32utils-...May/000386.htmlStep 2: Point Your Save Game Files To The New DirectoryNow that you have dynamically created a directory for your user, you need to make sure that your save files write to this directory, and not to your game's directory.
1. In
Window_SaveFile, on line 22...
Replace this:
CODE
@filename = "Save#{@file_index + 1}.rxdata"
With this:
CODE
@filename = $appPath + "/" + "Save#{@file_index + 1}.rxdata"
2. In
Scene_Title, on line 49...
Replace this:
CODE
if FileTest.exist?("Save#{i+1}.rxdata")
With this:
CODE
if FileTest.exist?($appPath + "/" + "Save#{i+1}.rxdata")
3. In
Scene_File, around line 110...
Replace this:
CODE
return "Save#{file_index + 1}.rxdata"
With this:
CODE
return $appPath + "/" + "Save#{file_index + 1}.rxdata"
And that's that! If you have created an options file for your game, follow the same steps for it.
CreditsSpecial credit should be given to Eccid. I wasn't sure how to get the ball rolling onto this one until I saw his save script over at Creation Asylum
This post has been edited by amaranth: Aug 17 2009, 05:06 PM