Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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
sauver.png


Demo
none.

Script
Ruby:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#                         Sauvegarde Windows              

#  par berka                        v 1.0                   rgss2

#                       [url=http://www.rpgmakervx-fr.com]http://www.rpgmakervx-fr.com[/url]

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# Place it above main

# in an event, "call a script" command

# save  : open the save dialog

# load    : open the load dialog

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

module Berka

  module ChargApi

    $LOAD_PATH<<'./'

    Filtre=["Save",".rvdata"]

    Charger="Load a file"

    Sauver="Save the Game"

    Conf="The file %s already exists, replace it ?"

    ConfTitre="Confirmation"

    Ret="Scene_Map"

  end

end

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

def handle

  h=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l')

  h.call("Game","Title","",t="&#92;&#48;"*256,256,"./Game.ini")

  Win32API.new('user32','FindWindow','pp','i').call("RGSS Player",t.delete!("&#92;&#48;"))

end

include Berka::ChargApi

class Game_Interpreter;def list_clr;@list=nil;end;end

def load

  ret,filtre="&#92;&#48;"*1024,"#{Filtre[0]}(*#{Filtre[1]})&#92;&#48;*#{Filtre[1]}&#92;&#48;&#92;&#48;"

  arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Charger,

  0x800|0x1000|4,0,0,".",0,0,0,].pack("I3pI3pI4pIS2pI3")

  return if Win32API.new('comdlg32','GetOpenFileName','p','i').call(arg)==0

  Scene_File.new(false,false,true).read_save_data(f=File.open(ret.rstrip,"rb"))

  f.close;$scene=eval("$scene=#{Ret}.new")

end

def save

  ret,filtre="&#92;&#48;"*1024,"#{Filtre[0]}(*#{Filtre[1]})&#92;&#48;*#{Filtre[1]}&#92;&#48;&#92;&#48;"

  arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Sauver,

  4|0x1000|0x80000,0,0,".",0,0,0].pack("I3pI3pI4pIS2pI3")

  return if Win32API.new('comdlg32','GetSaveFileName','p','i').call(arg)==0

  save if !(confirm?(ret.rstrip)if FileTest.exist?(ret.rstrip))

  $game_map.interpreter.list_clr

  Scene_File.new(true,false,true).write_save_data(f=File.open(ret.rstrip,"wb"))

  f.close;$scene=eval("$scene=#{Ret}.new")

end

def confirm?(f)

  t=sprintf(Conf,f.split("\\")[-1].gsub(Filtre[1],""))

  Win32API.new('user32','MessageBox','lppl','i').call(0,t,ConfTitre,36)==6

end

Ruby:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 

#                          Sauvegarde Windows              

#  par berka                        v 1.0                    rgss1 

#                        http://www.rpgmakervx-fr.com 

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 

# Place it above main

# in an event, "call a script" command

# save    : open the save dialog

# load      : open the load dialog

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

module Berka

  module ChargApi

    $LOAD_PATH<<'./'

    Filtre=["Save",".rxdata"]

    Charger="Load a file"

    Sauver="Save the Game"

    Conf="The file %s already exists, replace it ?"

    ConfTitre="Confirmation"

    Ret="Scene_Map"

  end

end

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 

def handle 

  h=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l') 

  h.call("Game","Title","",t="\0"*256,256,"./Game.ini") 

  Win32API.new('user32','FindWindow','pp','i').call("RGSS Player",t.delete!("\0")) 

end 

class Interpreter;def list_clr;@list=nil;end;end 

def load 

  ret,filtre="\0"*1024,"#{Berka::ChargApi::Filtre[0]}( 

      *#{Berka::ChargApi::Filtre[1]})\0*#{Berka::ChargApi::Filtre[1]}\0\0" 

  arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Berka::ChargApi::Charger, 

  0x800|0x1000|4,0,0,".",0,0,0,].pack("I3pI3pI4pIS2pI3") 

  return if Win32API.new('comdlg32','GetOpenFileName','p','i').call(arg)==0 

  Scene_Load.new.read_save_data(f=File.open(ret.rstrip,"rb")) 

  f.close;$scene=eval("$scene=#{Berka::ChargApi::Ret}.new") 

end 

def save

  ret,filtre="\0"*1024,"#{Berka::ChargApi::Filtre[0]}( 

      *#{Berka::ChargApi::Filtre[1]})\0*#{Berka::ChargApi::Filtre[1]}\0\0" 

  arg=[76,handle,0,filtre,0,0,1,ret,ret.size,0,0,0,Berka::ChargApi::Sauver, 

  4|0x1000|0x80000,0,0,".",0,0,0].pack("I3pI3pI4pIS2pI3") 

  return if Win32API.new('comdlg32','GetSaveFileName','p','i').call(arg)==0 

  save if !(confirm?(ret.rstrip)if FileTest.exist?(ret.rstrip)) 

  $game_system.map_interpreter.list_clr 

  Scene_Save.new.write_save_data(f=File.open(ret.rstrip,"wb")) 

  f.close;$scene=eval("$scene=#{Berka::ChargApi::Ret}.new") 

end 

def confirm?(f) 

  t=sprintf(Berka::ChargApi::Conf,f.split("\\")[-1].gsub(Berka::ChargApi::Filtre[1],"")) 

  Win32API.new('user32','MessageBox','lppl','i').call(0,t,Berka::ChargApi::ConfTitre,36)==6 

end
Instructions
In an Event, 'call a script' command:
to save the game
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
 
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?
 
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...
Code:
$scene=eval("$scene=#{Ret}.new")

use this:
Code:
 

    Ret=Scene_Map # see the missing "

#...

    $scene= Ret.new

 
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..

Code:
 

Ret = "Scene_Map"

#...

$scene = Object.const_get(Ret).new

 
or use procs
Code:
 

Ret = proc { $scene = Scene_Map.new }

#...

Ret.call

 
 
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.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top