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 VX 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!
DemoDownload Demo HereStep 1: Put Utils.dll in your project's folderAt the bottom of this post is a ZIP that contains
Utils.dll. Download and Unzip this file into the directory for your game. If you've done this right, Utils.dll will appear beside your game.exe in the directory for your game.
Step 2: 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
#------------------------------------
# Folder Settings
#------------------------------------
# Create Your Folder
SetEnv = Win32API.new('Utils', "AVSetEnv", ["V"], "I")
env = SetEnv.call
raise "UTILS: AVSetEnv failed!" if (!env)
path = " " * 256
path = ENV['AV_APPDATA'].rstrip
$appPath = path.to_s + "\\Aveyond 3"
# Create Your Folder
if !File.exists?($appPath)
Dir.mkdir($appPath)
end
Note: This 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!
Step 3: 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 23...
Replace this:
CODE
@filename = filename
With this:
CODE
@filename = $appPath + "\\" + "Save#{@file_index}.rvdata"
2. In
Scene_Title, on line 130...
Replace this function:
CODE
def check_continue
@continue_enabled = (Dir.glob('Save*.rvdata').size > 0)
end
With this function:
CODE
def check_continue
for i in 0..8
if FileTest.exist?($appPath + "\\" + "Save#{i}.rvdata")
@continue_enabled = true
end
end
end
3. In
Scene_File, on line 158...
Replace this:
CODE
return "Save#{file_index + 1}.rvdata"
With this:
CODE
return $appPath + "\\" + "Save#{file_index}.rvdata"
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: Feb 1 2010, 11:39 AM