RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Undefined method that I know I defined.

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 83
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 for:
Game_Actor
Code: [Select]
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
Code: [Select]
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


Can anyone explain to me what I am or am not doing to deserve this error?




« Last Edit: October 23, 2009, 08:18:16 PM by Doitsu »
My life is like every script I write: It runs great except for the f*cked up bits.

**
Rep:
Level 83
Detective Scrotes
The error is this line I believe.
Code: [Select]
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
Code: [Select]
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
Code: [Select]
return actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]
to
Code: [Select]
actor.equip_set[0, 5] = [actor.weapon_id,actor.armor1_id,actor.armor2_id,actor.armor3_id,actor.armor4_id]