I'm writing a lite script for granting skills from equiped items(yes I know there is one here already but I need the practice)
So I start my game and it runs fine, except when i go to change equipment, it says
Line 52 of the Module
Undefined Method 'equip_set=' for (insert actor hex address)
Anyways here's the code relating to my error...
[spoiler]
Game_Actor
class Game_Actor < Game_Battler
attr_accessor :last_skill_set # Copy current skills for updates
attr_accessor :skill_set # Current set of skills
attr_accessor :equip_set # Array of Equipment IDs # Right here, doesn't this define it?
attr_accessor :last_equip_set # Copy of Equipment IDs for updates
alias SGE_initialize initialize
def initialize(actor_id)
SGE_initialize(actor_id)
@actor= $data_actors[actor_id]
@skill_set= Array.new(5, Array.new)
@last_skill_set= Array.new(5, Array.new)
@equip_set= Array.new(5) # Here too, am I doing anything wrong?
@last_equip_set= Array.new(5)
end
Module
module SKRenSGE
#==========================================================================#
# ** Skill Index: #
#--------------------------------------------------------------------------#
# This is where you set up what skill are given by which equipment. #
# The format is: #
# {Equip ID 1=> [Skill ID 1, Skill ID 2,..., Skill ID N],..., Equip ID N}#
# Place all skills within the array you want to be granted by the #
# corresponding equipment. #
#==========================================================================#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
SKILL_INDEX_WEAPON= {1=>[2,3,4,5,6]}
SKILL_INDEX_ARMOR= {}
def self.skill_index(actor)
for i in 0..4
if i == 0
actor.skill_set[i]= SKILL_INDEX_WEAPON[actor.equip_set[i]]
else
actor.skill_set[i]= SKILL_INDEX_ARMOR[actor.equip_set[i]]
end
end
actor.last_skill_set = actor.skill_set
end
def self.equipment_skill_grant(actor)
for i in 0..4
for s in actor.skill_set[i]
actor.learn_skill[s]
end
end
end
def self.equipment_skill_removal(actor)
for i in 0..4
for s in actor.last_skill_set[i]
actor.forget_skill[s]
end
end
end
def self.update_equip_set(actor)
# This is the line that the error refers to
return actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]
end
def self.update_skills(actor)
SKRenSGE::update_equip_set(actor)
if actor.equip_set != actor.last_equip_set
SKRenSGE::equipment_skill_removal(actor)
SKRenSGE::skill_index(actor)
SKRenSGE::equipment_skill_grant(actor)
end
actor.last_equip_set = actor.equip_set
end
end
[/spoiler]
Can anyone explain to me what I am or am not doing to deserve this error?
The error is this line I believe.
return actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]
What you are doing is assigning the array with the values after the equal sign, however you also wrote a return statement. Remove return and see if that works. I'm pretty sure you cannot assign a variable in the same line that you are doing a return. Also, when you call that function in the update_skills function
SKRenSGE::update_equip_set(actor)
You aren't assigning a variable to that. If you expected the update_equip_set function to return a value you would need to store that value somewhere.
So, just change
return actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]
to
actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]