Save and Load Menu in APIs

Save and Load Menu in APIs
v1.0
By: Berka


Introduction
This script is perfectly useless, but I enjoyed creating it.
It allows the management of backups with the default Windows' Load/Save system

Features
  • Check if the file already exists
  • Saves can leave the project's directory.

Screenshots
Image

Demo
none.

Script
RMVX Spoiler
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #                                      Sauvegarde Windows                   
  3. #   par berka                                   v 1.0                            rgss2
  4. #                                   http://www.rpgmakervx-fr.com
  5. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  6. # Place it above main
  7. # in an event, "call a script" command
  8. # save  : open the save dialog
  9. # load     : open the load dialog
  10. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  11. module Berka
  12.   module ChargApi
  13.      $LOAD_PATH<<'./'
  14.      Filtre=["Save",".rvdata"]
  15.      Charger="Load a file"
  16.      Sauver="Save the Game"
  17.      Conf="The file %s already exists, replace it ?"
  18.      ConfTitre="Confirmation"
  19.      Ret="Scene_Map"
  20.   end
  21. end
  22. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. def handle
  24.   h=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l')
  25.   h.call("Game","Title","",t="&#92;&#48;"*256,256,"./Game.ini")
  26.   Win32API.new('user32','FindWindow','pp','i').call("RGSS Player",t.delete!("&#92;&#48;"))
  27. end
  28. include Berka::ChargApi
  29. class Game_Interpreter;def list_clr;@list=nil;end;end
  30. def load
  31.   ret,filtre="&#92;&#48;"*1024,"#{Filtre[0]}(*#{Filtre[1]})&#92;&#48;*#{Filtre[1]}&#92;&#48;&#92;&#48;"
  32.   arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Charger,
  33.   0x800|0x1000|4,0,0,".",0,0,0,].pack("I3pI3pI4pIS2pI3")
  34.   return if Win32API.new('comdlg32','GetOpenFileName','p','i').call(arg)==0
  35.   Scene_File.new(false,false,true).read_save_data(f=File.open(ret.rstrip,"rb"))
  36.   f.close;$scene=eval("$scene=#{Ret}.new")
  37. end
  38. def save
  39.   ret,filtre="&#92;&#48;"*1024,"#{Filtre[0]}(*#{Filtre[1]})&#92;&#48;*#{Filtre[1]}&#92;&#48;&#92;&#48;"
  40.   arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Sauver,
  41.   4|0x1000|0x80000,0,0,".",0,0,0].pack("I3pI3pI4pIS2pI3")
  42.   return if Win32API.new('comdlg32','GetSaveFileName','p','i').call(arg)==0
  43.   save if !(confirm?(ret.rstrip)if FileTest.exist?(ret.rstrip))
  44.   $game_map.interpreter.list_clr
  45.   Scene_File.new(true,false,true).write_save_data(f=File.open(ret.rstrip,"wb"))
  46.   f.close;$scene=eval("$scene=#{Ret}.new")
  47. end
  48. def confirm?(f)
  49.   t=sprintf(Conf,f.split("\\")[-1].gsub(Filtre[1],""))
  50.   Win32API.new('user32','MessageBox','lppl','i').call(0,t,ConfTitre,36)==6
  51. end
Expand to see the code.


RMXP Spoiler
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #                                       Sauvegarde Windows                     
  3. #   par berka                                    v 1.0                              rgss1
  4. #                                    http://www.rpgmakervx-fr.com
  5. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  6. # Place it above main
  7. # in an event, "call a script" command
  8. # save      : open the save dialog
  9. # load         : open the load dialog
  10. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  11. module Berka
  12.   module ChargApi
  13.      $LOAD_PATH<<'./'
  14.      Filtre=["Save",".rxdata"]
  15.      Charger="Load a file"
  16.      Sauver="Save the Game"
  17.      Conf="The file %s already exists, replace it ?"
  18.      ConfTitre="Confirmation"
  19.      Ret="Scene_Map"
  20.   end
  21. end
  22. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. def handle
  24.   h=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l')
  25.   h.call("Game","Title","",t="\0"*256,256,"./Game.ini")
  26.   Win32API.new('user32','FindWindow','pp','i').call("RGSS Player",t.delete!("\0"))
  27. end
  28. class Interpreter;def list_clr;@list=nil;end;end
  29. def load
  30.   ret,filtre="\0"*1024,"#{Berka::ChargApi::Filtre[0]}(
  31.          *#{Berka::ChargApi::Filtre[1]})\0*#{Berka::ChargApi::Filtre[1]}\0\0"
  32.   arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Berka::ChargApi::Charger,
  33.   0x800|0x1000|4,0,0,".",0,0,0,].pack("I3pI3pI4pIS2pI3")
  34.   return if Win32API.new('comdlg32','GetOpenFileName','p','i').call(arg)==0
  35.   Scene_Load.new.read_save_data(f=File.open(ret.rstrip,"rb"))
  36.   f.close;$scene=eval("$scene=#{Berka::ChargApi::Ret}.new")
  37. end
  38. def save
  39.   ret,filtre="\0"*1024,"#{Berka::ChargApi::Filtre[0]}(
  40.          *#{Berka::ChargApi::Filtre[1]})\0*#{Berka::ChargApi::Filtre[1]}\0\0"
  41.   arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Berka::ChargApi::Sauver,
  42.   4|0x1000|0x80000,0,0,".",0,0,0].pack("I3pI3pI4pIS2pI3")
  43.   return if Win32API.new('comdlg32','GetSaveFileName','p','i').call(arg)==0
  44.   save if !(confirm?(ret.rstrip)if FileTest.exist?(ret.rstrip))
  45.   $game_system.map_interpreter.list_clr
  46.   Scene_Save.new.write_save_data(f=File.open(ret.rstrip,"wb"))
  47.   f.close;$scene=eval("$scene=#{Berka::ChargApi::Ret}.new")
  48. end
  49. def confirm?(f)
  50.   t=sprintf(Berka::ChargApi::Conf,f.split("\\")[-1].gsub(Berka::ChargApi::Filtre[1],""))
  51.   Win32API.new('user32','MessageBox','lppl','i').call(0,t,Berka::ChargApi::ConfTitre,36)==6
  52. end
Expand to see the code.

Instructions
In an Event, 'call a script' command:
Quote:
save
to save the game
Quote:
load
to load the game

FAQ
Place the script above main

Compatibility
I really don't know!

Credits and Thanks
Msdn

Terms and Conditions
Free for using, but I need credits. Do not post this script anywhere without my permission !

enjoy !

berka
why make a script thats useless?? I don't think I'm gonna test it out either
How about XP version? This reminds me some older game. ;)
Okay, version Xp added !

berka
obsorber wrote:
why make a script thats useless?? I don't think I'm gonna test it out either

Some people might find use for this, you don't need to go around bashing things unnecessarily.
For XP, you'll need to change file extension at 'Filtre' to 'rxdata'. Anyway, if I want to call it from script(not from event), how should I do?
only with:
  1. save
Expand to see the code.


^^
(i'll whange the file's extension, thanks)

berka
why do you set "$LOAD_PATH" ?
you dint use it or did you?
No, it doesn't do anything, you can load file which are out of the project directory !
I've put it there at first

berka
i mean you didnt have a method witch is reading the global variable or?

PS:

this is very worse...
  1. $scene=eval("$scene=#{Ret}.new")
Expand to see the code.


use this:
  1.  
  2.      Ret=Scene_Map # see the missing "
  3. #...
  4.      $scene= Ret.new
  5.  
Expand to see the code.

this is better and faster
$LOAD_PATH is a special global variable which doesn't need to be read: it expends the current path of the project

Thanks for the codeline, but I have a convention: my settings module contains only strings or numbers. And the script may be pasted above the Scene_Map

best regards,
berka
only stings?
ok..

  1.  
  2. Ret = "Scene_Map"
  3. #...
  4. $scene = Object.const_get(Ret).new
  5.  
Expand to see the code.

or use procs
  1.  
  2. Ret = proc { $scene = Scene_Map.new }
  3. #...
  4. Ret.call
  5.  
Expand to see the code.
ok !
I'm defeated :lol:

thanks !
berka
I'm not bashing it, read those lines carefully before you make a comment...
but he said it himself that it was pointless. It puts me off testing it out if he
says it's a pointless script. And yes...maybe someone will find use for it, not me
tho...which is why I'm definately not testing it.

This script reminds me of rpg toolkit's method of saving and loading which
was really bugged as well. I disliked it a lot.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=63052