Main Menu
  • Welcome to The RPG Maker Resource Kit.

[XP] Class Inheritance, Im missing something...

Started by Heretic86, March 22, 2012, 04:18:12 AM

0 Members and 1 Guest are viewing this topic.

Heretic86

Besides my mind, I lost that a long time ago...

I created a new property for objects created inside class Game_Character, and that seems to be working just fine and dandy, but Im trying to offer a 2nd way to do the same thing by using an events name.  Regular Expression.  That is working just fine as well. 

What I came to the conclusion of is I need to do the same thing I did to Game_Character inside Game_Event < Game_Character.  Game_Event inherits properties and methods defined inside Game_Character, super has already been called.  But I cant seem to figure out why I cant access the property that was defined and inherited from _Character inside the inheriting class?

Yes, I am using attr_accessor :new_property in Game_Character, so how come I cant read that property in Game_Event?
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

modern algebra

I think I'm going to have to see the code to be able to help, since I don't see any problem with what you described. Ie. I think you are saying the arrangement is like this:


class Game_Character
  attr_accessor :new_property
  alias heretic86_initialz_newpr_2km3 initialize
  def initialize(*args, &block)
    @new_property = 0
    heretic86_initialz_newpr_2km3(*args, &block)
  end
end

class Game_Event
  alias hertic_initiz_5mx6 initialize
  def initialize(*args, &block)
    hertic_initiz_5mx6(*args, &block)
    p new_property # <- That will be defined as 0
  end
end


That is what you have described and that would work fine. The only thing I can think of is that is not what you intended to describe and I misinterpreted, so please show me the code which you are saying does not work.

Heretic86

That is exactly what I thought I was doing.  Alias and all.  Only difference I see is class Game_Event and mine is class Game_Event < Game_Character.  Oh wait, crap, I think I just figured it out.  In your example, wouldnt I still access new_property with @new_property with having the @ symbol (as defined above)?

edit:  Dammit!  I changed event.new_property (event was being passed as an arg in initialize) to @new_property and works fine now.  Ok I feel stupid.  Your example actually completely helped!
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!