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

Moving day is on May 12! A month from today! I'm finally getting my own apartment!
I made the logo and title screen for my game (Still rough but at least it's got a design now)
Eyy1s2gXIAMzfFN
Eyy1s2hXMAEmiRA
BCj
Whelp, it's been a while. Had another retina surgery on april 1st on my left eye. Well, 4 time's the charm, right? *recovery mode on*
The next JABS update will include ally AI and an aggro system.

Question:
What would YOU expect to happen if you had four+ party members in an ABS, all fighting either together or separately or a mix of the two, and the player hits "swap leader" button?
It currently pulls all followers to the player's location, removes all aggro towards enemies, and swaps them.
Time to wear a new face again...

Should keep things interesting huh? @EpicFILE :p

Forum statistics

Threads
110,336
Messages
1,052,453
Members
143,379
Latest member
sainti
Top