SaveUpdate Scriptlet
#1
SaveUpdate Scriptlet

ACE Version

by Kyonides Arkanthes


Introduction

There was a user that once wanted to add a very specific feature to the game header, namely the current map's name. Well, this scriptlet should let you modify all of your existing saved games by automatically adding that name to the hash for you.

Warnings
  • It has no GUI at all, guys! Tongue sticking out
  • This is a temporary scriptlet. Do not include it your official releases!
  • Be wise and backup the game files beforehand.

Code:
# * SaveUpdate Scriptlet ACE * #
#  Scripter : Kyonides Arkanthes
#  2023-04-09

# This scriptlet facilitates the update of your old saved games by adding
# secondary features like Current Map's Name and the like to the header.
# It has no graphical interface at all. Not like it ever needed one, though.

# * Scriptlet Published and Distributed AS IS. * #
# I might refuse any user's request for upgrade or maintenance releases. #

module SaveUpdate
  FILENAME_TEMPLATE = 'Save*.rvdata2'
  INCLUDE_MAPNAME = true
  extend self
  @header = {}
  def extend_header
    if INCLUDE_MAPNAME
      @header[:map_name] = $game_map.display_name
    end
  end

  def load_game_file(filename)
    File.open(filename, "rb") do |file|
      @header = Marshal.load(file)
      contents = Marshal.load(file)
      DataManager.extract_save_contents(contents)
    end
  end

  def save_game_file(filename)
    extend_header
    File.open(filename, "wb") do |file|
      Marshal.dump(@header, file)
      Marshal.dump(DataManager.make_save_contents, file)
    end
    @header.clear
  end

  def update_game_file(filename)
    load_game_file(filename)
    save_game_file(filename)
  end

  def clear_global_vars
    $game_system        = nil
    $game_timer        = nil
    $game_message      = nil
    $game_switches      = nil
    $game_variables    = nil
    $game_self_switches = nil
    $game_actors        = nil
    $game_party        = nil
    $game_troop        = nil
    $game_map          = nil
    $game_player        = nil
  end

  def run
    filenames = Dir.glob(FILENAME_TEMPLATE).sort
    if filenames.empty?
      msgbox "SaveUpdate Script Notice:\nNo game file was ever found!"
      return
    end
    DataManager.load_normal_database
    filenames.each{|fn| update_game_file(fn) }
    clear_global_vars
  end
  run
end


Terms & Conditions

Free for use in any kind of game.
Do not repost it anywhere!
Do not make any personal requests!
Distributed AS IS.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   VX Windowskin Scriptlet kyonides 0 5,343 03-13-2010, 02:02 AM
Last Post: kyonides



Users browsing this thread: 1 Guest(s)