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 Profile Posts

Well, I've decided I'll take a break on making Forgotten Eclipse...and Make a mod for FNF
Trailer for my new game.
last one for a while
MythicRuss wrote on gothicvoid's profile.
hi, i was looking thru ur awesome stuff, and was looking around the internet, how in the heckin heck do i get the hiddendoors to open? im addng them to the doors event but they just appear as solid walls, btw am total noob lol

Forum statistics

Threads
110,308
Messages
1,052,195
Members
143,343
Latest member
DarkValkyrieSin
Top