Data does not save

I am currently making a a fast travel/world map script and I am having a problem. I can't seem to "save" a certain command status when I save and exit the game. Meaning whenever I unlock "Map 1" via a script call, "Map 1" appears in my World Map, but when I save and exit and continue playing once again, it is not there anymore. I have done edits on DataManager as well but it does not seem to save the data, here is the script:



#==============================================================================#------------------------------------------------------------------------------# *** HSBX World Map# ** Author: Verheffen# ** Version: 0.0.1-pre-alpha#------------------------------------------------------------------------------$imported = {} if $imported.nil?#==============================================================================module HSBX module World_Map #========================================================================== #//////////////////////////// EDITABLE REGION ///////////////////////////// # World Map Settings WORLD_MAP = Cache.picture("WorldMap") MAP_COMMAND_VISIBLE = true # World Map Locations Locations = { :thilonde => ["Thilonde", true, 2, 8, 8 ], :elegiond => ["Elegiond", true, 2, 4, 8 ], :hargothrien => ["Hargothrien", true, 2, 6, 9], :tiressea => ["Tiressea", false, 2, 8, 8], :edheverand => ["Edhevrand", false, 2, 8, 9], } #////////////////////////// END EDITABLE REGION /////////////////////////// #========================================================================== endend#==============================================================================# ** Scene_WorldMap#------------------------------------------------------------------------------# Handles World Map scene#==============================================================================class Scene_WorldMap < Scene_Base include HSBX::World_Map #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start super() create_background create_map_command create_map_header create_map_desc end #-------------------------------------------------------------------------- # * Post-Start Processing #-------------------------------------------------------------------------- def post_start super() end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super() SceneManager.return if Input.trigger?🙂 end #-------------------------------------------------------------------------- # * Pre-Termination Processing #-------------------------------------------------------------------------- def pre_terminate super() end #-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate super() dispose_background dispose_map_command dispose_map_header dispose_map_desc end #-------------------------------------------------------------------------- # * Create Background #-------------------------------------------------------------------------- def create_background @background_sprite = Sprite.new @background_sprite.bitmap = WORLD_MAP end #-------------------------------------------------------------------------- # * Create Command Window #-------------------------------------------------------------------------- def create_map_command @map_command_window = Window_MapCommand.new(Graphics.width - 160, 48) @map_command_window.visible = true #MAP_COMMAND_VISIBLE Locations.each_key do |key| @map_command_window.set_handler(key, method🙂test_map)) end end def test_map p(@map_command_window.current_symbol) @map_command_window.activate end #-------------------------------------------------------------------------- # * Create World Map Header #-------------------------------------------------------------------------- def create_map_header @map_header = Window_MapHeader.new @map_header.x = Graphics.width - 160 @map_header.y = 0 @map_header.set_text("Locations:") end #-------------------------------------------------------------------------- # * Create Map Desc #-------------------------------------------------------------------------- def create_map_desc @map_desc = Window_MapDesc.new @map_desc.x = 0 @map_desc.y = 0 @map_desc.openness = 255 end #-------------------------------------------------------------------------- # * Free Background #-------------------------------------------------------------------------- def dispose_background @background_sprite.dispose end #-------------------------------------------------------------------------- # * Free Map Command #-------------------------------------------------------------------------- def dispose_map_command @map_command_window.dispose unless @map_command_window.disposed? end #-------------------------------------------------------------------------- # * Free World Map Header #-------------------------------------------------------------------------- def dispose_map_header @map_header.dispose unless @map_header.disposed? end #-------------------------------------------------------------------------- # * Free Map Desc #-------------------------------------------------------------------------- def dispose_map_desc @map_desc.dispose unless @map_desc.disposed? endend#==============================================================================# ** Window_MapCommand#------------------------------------------------------------------------------# Window that contains the selectable locations.#==============================================================================class Window_MapCommand < Window_Command include HSBX::World_Map #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width return 160 end #-------------------------------------------------------------------------- # * Get Window Height #-------------------------------------------------------------------------- def window_height return Graphics.height - fitting_height(1) end #-------------------------------------------------------------------------- # * Create Command List #-------------------------------------------------------------------------- def make_command_list Locations.each_key do |key| next unless Locations[key][1] add_command(Locations[key][0], key) end endend#==============================================================================# ** Window_MapDesc#------------------------------------------------------------------------------# Window that contains the location description.#==============================================================================class Window_MapDesc < Window_Message include HSBX::World_Map #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width return Graphics.width - 160 end #-------------------------------------------------------------------------- # * Get Window Height #-------------------------------------------------------------------------- def window_height return Graphics.height end #-------------------------------------------------------------------------- # * Draw Desc Text #-------------------------------------------------------------------------- def draw_text_desc(text) contents.clear draw_text_ex(0, 0, text) end #-------------------------------------------------------------------------- # * Wait After Output of One Character #-------------------------------------------------------------------------- def wait_for_one_character endend#==============================================================================# ** Window_MapHeader#------------------------------------------------------------------------------# This window shows skill and item explanations along with actor status.#==============================================================================class Window_MapHeader < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(line_number = 1) super(0, 0, Graphics.width, fitting_height(line_number)) end #-------------------------------------------------------------------------- # * Set Text #-------------------------------------------------------------------------- def set_text(text) if text != @text @text = text refresh end end #-------------------------------------------------------------------------- # * Clear #-------------------------------------------------------------------------- def clear set_text("") end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh contents.clear draw_text_ex(4, 0, @text) endend#==============================================================================# ** World_Map#------------------------------------------------------------------------------# This class performs World Map crap.#==============================================================================class World_Map include HSBX::World_Map # Enable Map def map_enable(symbol) Locations[symbol][1] = true endend#==============================================================================#------------------------------------------------------------------------------# *** Aliases and Sensitive Overwrites#------------------------------------------------------------------------------#==============================================================================#==============================================================================# ** Scene_Map#------------------------------------------------------------------------------# This class performs the map screen processing.#==============================================================================class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias :hsbx_worldmap_scenemap_update :update #-------------------------------------------------------------------------- def update hsbx_worldmap_scenemap_update update_world_map end #-------------------------------------------------------------------------- # * Update World Map #-------------------------------------------------------------------------- def update_world_map call_world_map if Input.trigger?🙂L) end #-------------------------------------------------------------------------- # * Call world map #-------------------------------------------------------------------------- def call_world_map SceneManager.call(Scene_WorldMap) end end#==============================================================================# ** DataManager#------------------------------------------------------------------------------# This module manages the database and game objects. Almost all of the # global variables used by the game are initialized by this module.#==============================================================================module DataManager #------------------------------------------------------------------------- # * Aliases #------------------------------------------------------------------------- class << self alias :hsbx_worldmap_datamanager_creategameobjects :create_game_objects alias :hsbx_worldmap_datamanager_makesavecontents :make_save_contents alias :hsbx_worldmap_datamanager_extractsavecontents :extract_save_contents end #-------------------------------------------------------------------------- # * Create Game Objects #-------------------------------------------------------------------------- def self.create_game_objects hsbx_worldmap_datamanager_creategameobjects() $world_map = World_Map.new end #-------------------------------------------------------------------------- # * Create Save Contents #-------------------------------------------------------------------------- def self.make_save_contents contents = hsbx_worldmap_datamanager_makesavecontents contents[:worldmap] = $world_map contents end #-------------------------------------------------------------------------- # * Extract Save Contents #-------------------------------------------------------------------------- def self.extract_save_contents(contents) hsbx_worldmap_datamanager_extractsavecontents(contents) $world_map = contents[:worldmap] endend 
In your World_Map class, you are using a constant variable, when you should be using an instance variable. Constant variables aren't saved with an instance of a class. Do you come from Java or C, by chance? 😛

So this part of your code:

class World_Map include HSBX::World_Map # Enable Map def map_enable(symbol) Locations[symbol][1] = true endendShould become this:
Code:
class World_Map  include HSBX::World_Map  def initialize    @locations = {}  end    def enabled?(symbol)    !!@locations[symbol] # The !! at the beg. converts to either true or false.  end    # Enable Map  def map_enable(symbol)    @locations[symbol] = true  endend
Now, when you want to check if a location is enabled, simply call $world_map.enabled?(symbol)EDIT: Technically, you don't even need the class World_Map, you could just assign $world_map as a hash, and just check:

Code:
$world_map[symbol] == true # or !!$world_map[symbol]
Thank you for your reply, indeed I come from Java and I'm still quite confused, even though I've been studying Ruby for quite a while now and I'm loving the language, but the transition seems to be slow 😛

Thank you, I now fixed the problem. But I do have one question though, is it possible to create a singleton class/module and put the locations there and just call it from the World_Map class and have the data saved?
I had similar problems coming over. The syntax is jarring as well.
The syntax is jarring as well.
Ha, I see what you did there 😛 @verheffen

Yeah, you have to get the static-ness of Jave out of your head, and that can be difficult to do if you've studied any C style language for a while. See, Ruby is both Object-Oriented and Functional, it used both paradigms at the same time.

To answer your question, your World_Map class is already what you need; given the code you posted, you've written this:

Code:
$world_map = World_Map.new
This is equivalent to Java's (I think this syntax is correct)
Code:
WorldMap myWorldMap; // Some global variable defined in a Java class file.// Later on down the road...myWorldMap = new WorldMap();
So, you are creating an instance of World_Map, and everything in this instance can be referenced one way or another. Given the code I gave you in my previous post, you can now check if a location is enabled, like so:
Code:
$world_map.enabled?(:thilonde)
It would return false, until you do this:
Code:
$world_map.enable(:thilonde)
If you are set on using World_Map to reference the data, then you can create a singleton method in World_Map like so:
Code:
class World_Map  def self.enabled?(sym)    $world_map.enabled?(sym)  endend# new game from title menu, then...$world_map.enable(:thilonde)World_Map.enabled?(:thilonde) # true!!!
Note that this singleton method will fail and raise an error if called before a new game is created or a game is loaded, because $world_map has not been set yet, so it's nil (equivalent to Java's null).
Thank you, FenixFyreX! I was able to solve my problem because of you!

Original thread: https://forums.rpgmakerweb.com/threads/data-does-not-save.34786/