I'm having trouble adding an attribute to 'class RPG::Weapon'. I'm not using any other scripts but I can't seem to add a class variable to the class previously mentioned. So I guess its time to see the code:
This script is located above main and below everything else. In Scene_Title right after all the database entries are loaded or I assume are loaded I create a Database_Init class and call alter_attr_weapons. Immediately it crashes the first time it encounters 'i.n_rarity = rand(3) + 1' claiming n_rarity is nil. Well I guess so since the 'RPG::Weapon's initialize was never encountered.
1.) So right off the bat does $data_weapons represent an array of 'RPG::Weapon's?
2.) Does the variable the accessor represents require declaration within the class? You just can't have the accessor you need the @variable somewhere in the functionality of the class?':|
I hope someone can help with this because I'm straining my tiny head for answers. And no misspellings this time I think.
Code:
class RPG::Weapon
RARITY_LEVELS = [1,2,3]
DEFAULT_RARITY = 0
attr_accessor :n_rarity
alias old_initialize initialize
def initialize
# Extra stuff added to the Weapon class.
@n_rarity = RARITY_LEVELS[DEFAULT_RARITY] # The rarity level of the weapon.
print("I acknowledge weapon has an initialize")
old_initialize
end
end
class Database_Init
def alter_attr_weapons
for i in $data_weapons
i.n_rarity = rand(3) + 1
end
end
end
This script is located above main and below everything else. In Scene_Title right after all the database entries are loaded or I assume are loaded I create a Database_Init class and call alter_attr_weapons. Immediately it crashes the first time it encounters 'i.n_rarity = rand(3) + 1' claiming n_rarity is nil. Well I guess so since the 'RPG::Weapon's initialize was never encountered.
1.) So right off the bat does $data_weapons represent an array of 'RPG::Weapon's?
2.) Does the variable the accessor represents require declaration within the class? You just can't have the accessor you need the @variable somewhere in the functionality of the class?':|
I hope someone can help with this because I'm straining my tiny head for answers. And no misspellings this time I think.