I've created this script that is supposed to give all items and equipment a variable called "space". I've created a script so I can use notetags for this:
module DRAGONISW
ITEM_SPACE = /<(?:SPACE|space):[ ](\d+)>/i
end # DRAGONISW
#==============================================================================
# ? DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_isw load_database; end
def self.load_database
load_database_isw
load_notetags_isw
end
#--------------------------------------------------------------------------
# new method: load_notetags_aim
#--------------------------------------------------------------------------
def self.load_notetags_isw
groups = [$data_items, $data_weapons, $data_armors]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_isw
end
end
end
end # DataManager
#==============================================================================
# ? RPG::BaseItem
#==============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :space
#--------------------------------------------------------------------------
# common cache: load_notetags_aim
#--------------------------------------------------------------------------
def load_notetags_isw
@space = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when DRAGONISW::ITEM_SPACE
@space = $1.to_i
end
} # self.note.split
#---
end
end # RPG::BaseItem
#==============================================================================
# Game_Interpreter
#==============================================================================
class Game_Interpreter
def inv_item_space
amount = 0
for i in 0..999
item = $data_items[i]
amount += $game_party.item_number(item) * item.space
end
return amount
end
end # Game_Interpreter
I try testing it out by calling the script code:
$game_variables[2] = inv_item_space
But I keep getting this error:
Script 'Game_Interpreter' line 1409: NoMethodError occurred.
undefined method `space' for nil:NilClass
I tried testing it on a brand new game and I still got this error. I've looked at many script that use notetags and it seems like I'm doing it correctly, so I don't understand what I'm doing wrong.