Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 GlobalValues XP
#1
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!
"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 }


Messages In This Thread
GlobalValues XP - by kyonides - 06-03-2023, 08:34 AM
RE: GlobalValues XP - by DerVVulfman - 06-04-2023, 04:29 PM
RE: GlobalValues XP - by kyonides - 06-04-2023, 04:57 PM



Users browsing this thread: