No experience scripting, multiple goals, requesting help

Zwataketa

Villager
Member
Joined
Nov 10, 2020
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMXP
Did that, but now the GlobalVar file isn't being created when it should be, and Global Variables aren't read from the file either ... Loading a save resets the variables to whatever they were on the save file.
Code:
module GlobalVar
  @@global_variable_data = nil
 
  def self.save
    @@global_variable_data = $game_variables.global_variables
    file = File.open('GlobalVar.rxdata', 'wb')
    Marshal.dump(@@global_variable_data, file)
    file.close
  end
 
  def self.load
    return @@global_variable_data unless @@global_variable_data.nil?
   
    file = File.open('GlobalVar.rxdata', 'rb')
    @@global_variable_data = Marshal.load(file)
    file.close
    @@global_variable_data
  end
 
  def self.exist?
    File.exist?('GlobalVar.rxdata')
  end
 
end

No Error messages this time.
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
351
Reaction score
136
First Language
English
Primarily Uses
RMXP
That's not the entirety of your script right? When I put them all together, it looked fine to me.
 

Zwataketa

Villager
Member
Joined
Nov 10, 2020
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMXP
That's not the entirety of your script right? When I put them all together, it looked fine to me.
Here's the entire GlobalVar script:
Code:
RANGE_OF_VARS = 50..52

module GlobalVar
  @@global_variable_data = nil
  
  def self.save
    @@global_variable_data = $game_variables.global_variables
    file = File.open('GlobalVar.rxdata', 'wb')
    Marshal.dump(@@global_variable_data, file)
    file.close
  end
  
  def self.load
    return @@global_variable_data unless @@global_variable_data.nil?
    
    file = File.open('GlobalVar.rxdata', 'rb')
    @@global_variable_data = Marshal.load(file)
    file.close
    @@global_variable_data
  end
  
  def self.exist?
    File.exist?('GlobalVar.rxdata')
  end
  
end

#module Graphics
#  class << self
#    alias clear_gs_cache_on_update update
#    def update
#      GlobalVar.clear_cache
#      clear_gs_cache_on_update
#    end
#  end
#end


class Game_Variables
  
  alias get_variable []
  def [](id)
    if id.between?(RANGE_OF_VARS.first, RANGE_OF_VARS.last) && GlobalVar.exist?
      @data.slice!(RANGE_OF_VARS)
      @data.insert(RANGE_OF_VARS.first, *GlobalVar.load)
    end
    get_variable(id)
  end
  
  alias set_variable []=
  def []=(id, val)
    set_variable(id, val)
    if id.between?(RANGE_OF_VARS.first, RANGE_OF_VARS.last)
      GlobalVar.save
    end
  end

  def global_variables
    @data[RANGE_OF_VARS.last] ||= 0
    @data[RANGE_OF_VARS]
  end
end
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
351
Reaction score
136
First Language
English
Primarily Uses
RMXP
Yeah, that's exactly what I have and it worked fine.
 

Zwataketa

Villager
Member
Joined
Nov 10, 2020
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMXP
Yeah, that's exactly what I have and it worked fine.
So, if you were to delete GlobalVar and then try to change one of the global variables afterward, it recreates the file as intended?
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
351
Reaction score
136
First Language
English
Primarily Uses
RMXP

Zwataketa

Villager
Member
Joined
Nov 10, 2020
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMXP
WAIT I'm silly. The variable I was trying to change was out of the specified range, and I never updated the range. Doh.

Yeah, with that knowledge, it works now. Sorry for the confusion.

And now Yuka can be a reindeer in game without fiddling with the debug menu. Yay. 1611816243643.png
 

Latest Threads

Latest Posts

Latest Profile Posts

unknown.png

A sketch of a character for an upcoming chapter. I am pre-preparing the heck out of this one and future chapters, don't want to spend time figuring the story out again. :blush:
Today *Fix the game UI
RMMZ maxRows make me tired.
The game supports real-time language switching (really interesting).
8laFKAa.png


jBYDFzZ.png


lYbvPth.png

mY99lgU.png

Swag collecting in the new randomly generated area. Now the mini map also shows the randomly generated features... And even illustrates the whole "bubble" system" that I made to manage memory... Though that part's inadvertent. We'll just call that "the fog of war"... Yes, that's what we'll do. Nobody will be the wiser! :kaopride:
not me being not lazy for 5 seconds and drawing another char portrait (her name is hazel)
its_hazel.png
Been a while since the last time I made a song remix. Had a blast making this

Forum statistics

Threads
110,456
Messages
1,053,450
Members
143,547
Latest member
Spoonman
Top