Help - Search - Members - Calendar
Full Version: Super Simple Custom Save System (VX)
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
amaranth
Introduction
If 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!

Demo
Download Demo Here

Step 1: Put Utils.dll in your project's folder
At 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 Startup
The 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 Directory
Now 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. smile.gif

Credits
Special 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
icecold49
Well this kinda neat. I myself use windows XP but this should be really useful for all you VX users who suffer with this saving problem. Thanks for the submission.
Zeriab
I like idea of trying to avoid saving problems with Vista biggrin.gif
What is important to note is that you can have a case where you do not have permission to write and/or read from the application data folder.
I am not too fond of creating a new environment variable when there is one present by standard in XP and Vista. (Dunno about earlier versions)

Personally I would use this version to determine where the saves are:
CODE
begin
  path = ENV['AV_APPDATA']
  $appPath = path.to_s + "\\YourGame"
  if !File.exists?($appPath)
    Dir.mkdir($appPath)
  end
rescue
  # Perhaps tell the player that there is a problem
  $appPath = "." # Use current directory
end


The reason for the rescue is to heighten the chance of the players being able to play the game.
An alternative choice or one that could be used in conjunction is to give the player the choice to change the location of the save files. It could for example be present in the game.ini file.

I think you have a good idea. I just think it can be improved happy.gif
*hugs*
- Zeriab
buny
Demo...demo demo...demo demoooo
platipus
what's the benefits of using this "super simple" custom save system?
any screenshot?
redyugi
What this is used for, Platipus, is to work around Vista's annoying habit of needing password input to write files or access files. This really should be renamed because I thought it was something different too. That being said, I am not using this, mainly because I finally got rid of Vista, and I am done with finding ways around it. lolz
platipus
@redyugi

ah okay got it. :]

i dont think i'll be needing it since im not a vista user.
Zeriab
There are more implications than just allowing Vista users to save if the game is placed in the Program Files.
Let's say you delete the game and install it again, or install it in another place. The save files will still be there.
It also makes the importation of episodic games easier since you can easily locate saves from the previous game.

The downside is that the Application Data folder is hidden by default in Vista. There can also be some permission problems.
It does not work well if you have games on an USB stick so you can play the game on arbitrary computers.

*hugs*
amaranth
Hey Zeriab, the reason we created an environmental variable is because rpg maker games crash when you save to the %appdata% folder and your profile has a non-English character in it (like ABIGAƍL). The only way around this problem that we could find was to create a variable that generated the short version of the profile name. Does this make sense?

By default, most games today store their data in the %appdata% folder, so this is usually the safest place to put it. It's the standard that all of the game portals seem to require as well.

If you have a way to avoid creating a new environmental variable can you let me know? I can update this as needed and add you to the credits.

smile.gif
Zeriab
Hey Amanda happy.gif
I never considered the problems of non-English characters.
I got no crashing when I tested it, but I found that FileTest could not detect files in there. Removing the checks I had no problems loading (and saving) the files.
I'm not really sure what to do about it, but I will definitely let you know if I find another way. (Unless it's very unsafe)

It's true that many games store their data in that folder. A couple store it in My Documents.
I think you can be right in that folder usually being the safest place, but not always. The only danger of having an opt-in feature of an alternate save location is the increase in complexity of the save system. Considering that the small size makes transportation on USB stick and etc feasible I would argue the gain is higher than the potential risk. You will be servicing the users more.

*hugs*
- Zeriab
amaranth
There were some bugs in the save code. I've fixed them. I've also attached a demo to this thread so you can see how it works.
ZeroManArmy
Screen shots?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.