undefined method: class_id for Game_Enemy

● ARCHIVED · READ-ONLY
Started by J_I 4 posts View original ↗
  1. I know this is a pretty rudimentary scripting question, but I'm quite new to scripting and spent all morning trying to find an answer. My situation is this:
     
    I have changed the TP gain upon hitpoint loss to only work for a certain class by scraping together the following code:
     

     #-------------------------------------------------------------------------- # * Charge TP by Damage Suffered #-------------------------------------------------------------------------- def charge_tp_by_damage(damage_rate)    if self.class_id == 3      self.tp += 50 * damage_rate * tcr    else      self.tp += 0 * damage_rate * tcr    end  endThis does its job well enough when the player gets hit, but the game crashes when I attack the enemy with this message: "undefined method 'class_id' for Game_Enemy"

    I understand the logic well enough to know that the script needs to know what to do in the case of a target with no class suffering damage, but I don't know what language to use to do so. I'm sure this is on the forum somewhere, but all I could find in my search was information about giving monsters classes, which (presumably) would work, but isn't exactly what I'm looking for.

    Help on this would be greatly appreciated. Thank you!
  2. You are using class Game_Enemy right? Game_Enemy doesn't have class_id if I'm not mistaken.

    Without looking through I would GUESS

    Game_Actor

    class Game_Actor  #--------------------------------------------------------------------------# * Charge TP by Damage Suffered#--------------------------------------------------------------------------  def charge_tp_by_damage(damage_rate)    if self.class_id == 3      self.tp += 50 * damage_rate * tcr    else      self.tp += 0 * damage_rate * tcr    end  endendThere you go.
  3. I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


    Remember - anything you do in the Game_Battler or Game_BattlerBase classes affect actors AND enemies. If you JUST want to do something with actors, you've got to do it in Game_Actor, as shown above.
  4. Thanks, guys! I moved the code to Game_Actor and left the default code under Game_Battler, and that seems to have done the trick.

    Many thanks for the quick and helpful replies.