How do I get the ruby-class of Game_Actor?

● ARCHIVED · READ-ONLY
Started by Tsukihime 9 posts View original ↗
  1. If you created a new project and made a script call

    p $game_actors[1].classIt will return "Soldier" instead of "Game_Actor"Evidently this is because Game_Actor overwrites `class`...

    How do I get the ruby-class name?

    Well, beyond doing this

    Code:
    class Game_Actor < Game_Battler    alias :th_rmxml_class :class  def class    if $XML_EXPORT      return Game_Actor    else      return th_rmxml_class    end  endend
  2. Well, this seems to work

    Code:
    class Object  alias :klass :classend
    Now you can just access `klass` instead and avoid running into issues with Game_Actor.
  3. Code:
    $game_actors[1].actor.class
    ??? I seem to remember having to do something a bit weird like this. Don't have time to test it now though.
  4. Shaz said:
    $game_actors[1].actor.class??? I seem to remember having to do something a bit weird like this. Don't have time to test it now though.
    It will return RPG::Actor
  5. Seems to be the right code then :)


    Unless you really wanted it to return Game_Actor Hime, and not RPG::Actor?
  6. Yes, I want it to return "Game_Actor" instead of "Soldier", which is the name of the actor's in-game class.
  7. yeah, the best I can come up with is RPG::Actor which is the class of $game_actor[id].actor
  8. A solution that doesn't define a new method:

    Object.instance_method:)class).bind($game_actors[1]).call # => Game_ActorEdit: Simplified a bit.
  9. That's pretty creative: calling something else's class method just to get around the fact that Game_Actor changed it.