Save-Point
GlobalValues XP - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: GlobalValues XP (/thread-8750.html)



GlobalValues XP - kyonides - 06-03-2023

GlobalValues XP

by Kyonides

Introduction

Once upon a weird time, there was a forumer that wanted to rewrite many saved games for no good reason.
What if there was a better solution? Thinking 
Yeah, like a Global Save File! Grinning

My scriptlet will handle almost everything on its own except for one single thing, namely the Game Over screen.
You got to make the script call by hand so to say. Tongue sticking out

The Script

Code:
# * GlobalValues XP * #
#  Scripter : Kyonides Arkanthes
#  v0.3.0 - 2023-06-03

# This script creates a new Global Variable and stores values there for future
# use in all game sessions.

# It will update the battle result variables automatically if you are using
# a Battle System that is compatible enough with the Default BS.

# Stats like Wins, Escapes, Losses, Saves, and Loads are already
# updated by the script automatically!

# * Script Calls * #

# - Access Wins:
#  $global_data.wins
# - Access Escapes:
#  $global_data.escapes
# - Access Losses:
#  $global_data.losses
# - Access Total Saves:
#  $global_data.saves
# - Access Total Loads:
#  $global_data.loads
# - Access or Update Total Gameovers:
#  $global_data.gameovers
#  $global_data.gameover!
# - Access or Update the Switch:
#  $global_data.switch
#  $global_data.switch = true
#  $global_data.switch = false

# * Optional - No Need for You to use them! * #

# - Create or Load the new Global Variable
#  Global.load_file

# - Save Global Data at Any Moment
#  Global.save_file

module Global
  # PATH = "" means the Game's Root Directory (RD)
  # PATH = "Saves" means the Saves Directory at the RD
  PATH = ""
  FILENAME = "GlobalValues.rxdata"
  class Values
    def initialize
      @wins = 0
      @escapes = 0
      @losses = 0
      @saves = 0
      @loads = 0
      @gameovers = 0
      @switch = nil
    end

    def save_result(result)
      case result
      when 0
        @wins += 1
      when 1
        @escapes += 1
      when 2
        @losses += 1
      end
      Global.save_file
    end

    def saved!
      @saves += 1
      Global.save_file
    end

    def loaded!
      @loads += 1
      Global.save_file
    end

    def gameover!
      @gameovers += 1
      Global.save_file
    end
    attr_accessor :wins, :escapes, :losses
    attr_accessor :saves, :loads, :gameovers, :switch
  end

  extend self
  def filename
    if PATH.empty?
      FILENAME
    else
      PATH + "/" + FILENAME
    end
  end

  def save_file
    save_data($global_data, filename)
  end

  def load_file
    if File.exist?(filename)
      $global_data = load_data(filename)
    else
      $global_data = Global::Values.new
      save_file
    end
  end
  load_file
end

class Scene_Save
  alias :kyon_global_values_scn_sv_wsd :write_save_data
  def write_save_data(file)
    kyon_global_values_scn_sv_wsd(file)
    $global_data.saved!
  end
end

class Scene_Load
  alias :kyon_global_values_scn_ld_rsd :read_save_data
  def read_save_data(file)
    kyon_global_values_scn_ld_rsd(file)
    $global_data.loaded!
  end
end

class Scene_Battle
  alias :kyon_global_values_scn_btl_btl_end :battle_end
  def save_global_data(result)
    $global_data.save_result(result)
  end

  def battle_end(result)
    save_global_data(result)
    kyon_global_values_scn_btl_btl_end(result)
  end
end


Terms & Conditions

Free for use in any game, as long as you don't complain at all.
Include my nickname in your game credits.
That's it!


RE: GlobalValues XP - DerVVulfman - 06-04-2023

So in essence this creates a new and separate saved-stats file, separate from traditional save-game files, that can record how many times the player saved a game, times the player engaged in battle, died, and so on.... in ALL their game playing rather than just per saved game session.

So the player may start a new game, fight two monsters, escaped once, and died.... and hadn't even made a save. These stats would still be recorded. Completely cumulative despite saving a game or not, and not individual per save-file.


RE: GlobalValues XP - kyonides - 06-04-2023

For some reason, the requester wanted to record all those stats no matter what the player did or tried to do to get some weird or despicable or maybe illegal? advantage.