- Joined
- Jul 22, 2014
- Messages
- 5,624
- Reaction score
- 5,104
- First Language
- English
- Primarily Uses
- RMVXA
I've come across some very strange behavior while modifying one of my scripts. The script creates a Hash called $lim_shops which tracks inventories for each individual store using the following format: $lim_shops.shops[shop_id][database_object] = number
This works fine in-game, but when I used pretty standard save/load aliasing to preserve the inventory values when the player comes back to the game, all of the shops' inventories are gone! After some debugging, it seems that the number for each shop/object combination somehow becomes nil during or after a Load, and I have no idea why this is happening. The Save itself doesn't seem to trigger this issue.
Here is the DataManager section of my script:
module DataManager
class << self
#--------------------------------------------------------------------------
# * Create Game Objects, including Shop Array
#--------------------------------------------------------------------------
alias :create_game_objects_with_shop_array :create_game_objects
def create_game_objects
create_game_objects_with_shop_array
$lim_shops = Limited_Shops.new
end
#--------------------------------------------------------------------------
# * Create Save Contents, including Shop Array
#--------------------------------------------------------------------------
alias :make_save_contents_with_shop_array :make_save_contents
def make_save_contents
contents = make_save_contents_with_shop_array
contents[:lim_shops] = $lim_shops
$game_variables[8] = contents[:lim_shops].shops[3][$data_weapons[1]] # TEST TEST
contents
end
#--------------------------------------------------------------------------
# * Extract Save Contents, including Shop Array
#--------------------------------------------------------------------------
alias :extract_save_contents_with_shop_array :extract_save_contents
def extract_save_contents(contents)
extract_save_contents_with_shop_array(contents)
$lim_shops = contents[:lim_shops]
$game_variables[6] = contents[:lim_shops].shops[3].size # TEST TEST
$game_variables[7] = contents[:lim_shops].shops[3][$data_weapons[1]] # TEST TEST
# TEST TEST: If this value is nil (it shouldn't be), play the SE
if (contents[:lim_shops].shops[3][$data_weapons[1]] == nil)
Audio.se_play('Audio/SE/Disappointment')
end
end
end
end
As you can see, I added several lines of "debug" code to see what's going on. At the start of my game, Shop #3 has 200 Hand Axes. After I save and check the game's variables, Variable 8 is 200, meaning that contents[:lim_shops] seems to be holding the valid, populated Hash. When I quit and load a game, then check the game's variables, I see that Variable 6 is set to 6, meaning that contents[:lim_shops].shops[3] is correctly holding 6 key-value pairs. But Variable 7 is still set to 0, and the "Disappointment" SE plays upon Loading to indicate that the value for contents[:lim_shops].shops[3][$data_weapons[1]] is inexplicably nil!
Testing was done in a completely clean project. I can provide the clean project with the full script if you think it would assist in solving this problem.
Please help me!! I am at a complete loss as to why the number is still fine after a Save, but is lost after a Load!
Thanks a million for your time.
This works fine in-game, but when I used pretty standard save/load aliasing to preserve the inventory values when the player comes back to the game, all of the shops' inventories are gone! After some debugging, it seems that the number for each shop/object combination somehow becomes nil during or after a Load, and I have no idea why this is happening. The Save itself doesn't seem to trigger this issue.
Here is the DataManager section of my script:
module DataManager
class << self
#--------------------------------------------------------------------------
# * Create Game Objects, including Shop Array
#--------------------------------------------------------------------------
alias :create_game_objects_with_shop_array :create_game_objects
def create_game_objects
create_game_objects_with_shop_array
$lim_shops = Limited_Shops.new
end
#--------------------------------------------------------------------------
# * Create Save Contents, including Shop Array
#--------------------------------------------------------------------------
alias :make_save_contents_with_shop_array :make_save_contents
def make_save_contents
contents = make_save_contents_with_shop_array
contents[:lim_shops] = $lim_shops
$game_variables[8] = contents[:lim_shops].shops[3][$data_weapons[1]] # TEST TEST
contents
end
#--------------------------------------------------------------------------
# * Extract Save Contents, including Shop Array
#--------------------------------------------------------------------------
alias :extract_save_contents_with_shop_array :extract_save_contents
def extract_save_contents(contents)
extract_save_contents_with_shop_array(contents)
$lim_shops = contents[:lim_shops]
$game_variables[6] = contents[:lim_shops].shops[3].size # TEST TEST
$game_variables[7] = contents[:lim_shops].shops[3][$data_weapons[1]] # TEST TEST
# TEST TEST: If this value is nil (it shouldn't be), play the SE
if (contents[:lim_shops].shops[3][$data_weapons[1]] == nil)
Audio.se_play('Audio/SE/Disappointment')
end
end
end
end
As you can see, I added several lines of "debug" code to see what's going on. At the start of my game, Shop #3 has 200 Hand Axes. After I save and check the game's variables, Variable 8 is 200, meaning that contents[:lim_shops] seems to be holding the valid, populated Hash. When I quit and load a game, then check the game's variables, I see that Variable 6 is set to 6, meaning that contents[:lim_shops].shops[3] is correctly holding 6 key-value pairs. But Variable 7 is still set to 0, and the "Disappointment" SE plays upon Loading to indicate that the value for contents[:lim_shops].shops[3][$data_weapons[1]] is inexplicably nil!
Testing was done in a completely clean project. I can provide the clean project with the full script if you think it would assist in solving this problem.
Please help me!! I am at a complete loss as to why the number is still fine after a Save, but is lost after a Load!
Thanks a million for your time.

