NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
Whenever the player dies, I want a variable to be increased in the already-existing Save File, without overwriting it whole, so that I can tell how many times they have died, maybe even where they died, and act accordingly with whatever other function I want the death count to have
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
Use a game variable then. They get saved by the game every... single... time!
 

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
Use a game variable then. They get saved by the game every... single... time!
It wouldn't get saved after a game over, I want to change the variable directly from the Save File, so that when a player loads the save again, the change will persist and take effect
 

Zeriab

Huggins!
Regular
Joined
Mar 20, 2012
Messages
1,405
Reaction score
1,617
First Language
English
Primarily Uses
Other
What would happen if the player loads another save file? Would that have a separate counter that counts loads?
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
A global save file would be a better solution...
 

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
A global save file would be a better solution...
Do you mean using only a single save file for the whole game, or a file that stores data that loads to all save files?
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
Nah, a single file separate from all save files. It'd only contain global stuff like times the player lost or whatever you wanna add to that list. The script would automatically load that file's data before or after loading the selected save file. It would be always available and you would have no need to alter already existing save files.
 

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
Nah, a single file separate from all save files. It'd only contain global stuff like times the player lost or whatever you wanna add to that list. The script would automatically load that file's data before or after loading the selected save file. It would be always available and you would have no need to alter already existing save files.
Do you have any script at hand that can do that
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
No worries. It can be made if it doesn't exist, yet.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
But since you want to get such an extra file, what else would you like to feed it with?
Tentatively, I'd name the main variable stored there "losses" if you don't mind.
 

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
But since you want to get such an extra file, what else would you like to feed it with?
Tentatively, I'd name the main variable stored there "losses" if you don't mind.
Well, I suppose a switch just incase would be pretty useful
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
46,153
Reaction score
16,960
First Language
English
Primarily Uses
RMMV
What would happen if the player loads another save file? Would that have a separate counter that counts loads?
A very relevant question here, that you have completely ignored @NardBruh
 

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
A very relevant question here, that you have completely ignored @NardBruh
Oh I'm sorry about that
What would happen if the player loads another save file? Would that have a separate counter that counts loads?
Well, for the game I had this idea for? My main desire is for the deaths to be remembered even if they're in different saves, but I'm perfectly fine with the opposite too
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
Here's the first version of my code...

You just need to find the best place to call the Global.load_file method.
Global.save_file will be called right after the battle ended but before the map is loaded.

EDITED in order to include a clarification.

Version 0.1.1

Ruby:
# * GlobalValues XP * #
#   Scripter : Kyonides Arkanthes
#   v0.1.1 - 2023-06-02
# * Outdated! * #
 
Last edited:

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
Here's the first version of my code...

You just need to find the best place to call the Global.load_file method.
Global.save_file will be called right after the battle ended but before the map is loaded.

EDITED in order to include a clarification.

Version 0.1.1

Ruby:
# * GlobalValues XP * #
#   Scripter : Kyonides Arkanthes
#   v0.1.1 - 2023-06-02

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

# Wins, Escapes & Losses are already updated by the script!

# * Script Calls * #

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

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

# - Access Wins:
#   $global_data.wins
# - Access Escapes:
#   $global_data.escapes
# - Access Losses:
#   $global_data.losses
# - Access or Update the Switch:
#   $global_data.switch
#   $global_data.switch = true
#   $global_data.switch = false

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
      @switch = nil
    end

    def save_result(result)
      case result
      when 0
        @wins += 1
      when 1
        @escapes += 1
      when 2
        @losses += 1
      end
    end
    attr_accessor :wins, :escapes, :losses, :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
    filename = path
    if File.exist?(filename)
      $global_data = load_data(filename)
    else
      $global_data = Global::Values.new
    end
  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)
    Global.save_file
  end

  def battle_end(result)
    save_global_data(result)
    kyon_global_values_scn_btl_btl_end(result)
  end
end
Well uh, winning a fight, escaping a fight and losing a fight lead to the game crashing, line 84 being stated as the issue by RPG Maker

Global.save_file works, but using load_file crashes the game, the same happens with the switch
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
No problem, I've come with an improved version of my script.

Version 0.2.1

Ruby:
# * GlobalValues XP * #
#   Scripter : Kyonides Arkanthes
#   v0.2.1 - 2023-06-02
# * Outdated! * #
 
Last edited:

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
No problem, I've come with an improved version of my script.

Version 0.2.1

Ruby:
# * GlobalValues XP * #
#   Scripter : Kyonides Arkanthes
#   v0.2.1 - 2023-06-02

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

# Wins, Escapes & Losses are already updated by the script!

# * 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 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
      @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
    attr_accessor :wins, :escapes, :losses, :saves, :loads, :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
Oh sweet, it works now!

Tho I feel like there should be another counter added for the amount of game overs you get, since losses only registers battle losses where you have "Continue Even When Loser" on, it doesn't count getting game overs as losses, I think that would make this script absolutely perfect
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,773
Reaction score
893
First Language
English
Primarily Uses
RMXP
=_= Why am I feeling like I am getting abused by someone here?
Yeah, I wonder why. :p

By the way, you gotta call $global_data.gameover! if the player ever gets a Game Over screen...

Version 0.3.0

Ruby:
# * GlobalValues XP * #
#   Scripter : Kyonides Arkanthes
#   v0.3.0 - 2023-06-03
# * Go straight to its Dedicated Thread * #
 
Last edited:

NardBruh

Regular
Regular
Joined
Jun 2, 2021
Messages
31
Reaction score
2
First Language
Portuguese
Primarily Uses
Other
=_= Why am I feeling like I am getting abused by someone here?
Yeah, I wonder why. :p

By the way, you gotta call $global_data.gameover! if the player ever gets a Game Over screen...

Version 0.3.0

Ruby:
# * 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
I'm sorry for making you feel like that

But now this script is perfect! Thank you so so much!
 

Latest Threads

Latest Posts

Latest Profile Posts

I’m so lucky! Simone got referred to a feline cardiologist and had I not called this morning the moment there was a cancellation the next opening would have been SEVEN months from now! The other heart hospital would have been on the other side of Michigan. Who knew that animal specialty appointments were also terrible to get!?
Scalemail project is one step closer to completion. Ordered scales from a local metalworking company, ordered some split rings... now all I need is to wait. :>
And pray that the split rings will be flexible enough to handle that.
A spooky banner and a spooky pfp for a spooky season.
Spooky-Season.png
Broke: Actually making the stuff you need to make before the game can progress.
Woke: Wasting time instead by making a sidequest where you can recruit an imaginary friend to the party.
1696264391516.png
Day 1 I don't know where to start... I enjoy designing icons and brainstorming the abilities my video game will have

Forum statistics

Threads
134,991
Messages
1,252,682
Members
177,897
Latest member
Haihai
Top