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

unknown.png

Making good progress with the second chapter. :)

Still work in progress.

(Real life, it is chronically the fourth chapter that I am making.)
constructionworkconcept.pngezgif-2-0acb620ecf8d.gifezgif-2-afeaf16ebb8d.gif "The Great Wall is great. But, most people can only be the slaves who built it, leaving their bones underneath that wall. They spent their whole life to build that wall and the empire, an empire that enslaves them." :kaoswt2: I'm just going to turn it into a modern-day sad tale.

No edits, just gameplay from one area to the next. Plus all my new shiny interface stuff... And I even remember to bolt down the portal so it won't escape this time. :kaopride:
You guys just freely offer up your Autonomy?
I don't know about you, but today the covid frustration is seriously getting to me. Haven't really seen many of my friends for two years, since i moved towns the year before this all started, and well, i miss them :(
so, here's a cute alpacaraptor sketch to heighten the mood:
W7Fhp9n.png

Forum statistics

Threads
110,660
Messages
1,055,022
Members
143,786
Latest member
Avigayil
Top