Confusing Error

● ARCHIVED · READ-ONLY
Started by Euphoria 3 posts View original ↗
  1. So this is my code, and if you can't tell, I'm working on making a "threat" gauge and will eventually set up enemy targeting based on threat levels.

    module Euphoria module Threat end module Regex THREAT_GEN = /<Threat:[-_ ]?(\d+)>/i endend#┌──────────────────────────────────────────────────────────────────────────────#│■ DataManager#└──────────────────────────────────────────────────────────────────────────────module DataManager class << self; alias euphoria_threat_datamanager_loaddatabase_15 load_database; end #ALIAS - LOAD_DATABASE def self.load_database euphoria_threat_datamanager_loaddatabase_15 load_threat_notetags end #NEW - LOAD_THREAT_NOTETAGS def self.load_threat_notetags groups = [$data_skills] for group in groups for obj in group next if obj.nil? obj.load_threat_notetags end end end end#┌──────────────────────────────────────────────────────────────────────────────#│■ RPG::Skill#└──────────────────────────────────────────────────────────────────────────────class RPG::Skill < RPG::UsableItem attr_accessor :threat_plus #NEW - LOAD_THREAT_NOTETAGS def load_threat_notetags @threat_plus = 0 self.note.scan(Euphoria::Regex::THREAT_GEN) @threat_plus = $1.to_i end end#┌──────────────────────────────────────────────────────────────────────────────#│■ Game_Battler#└──────────────────────────────────────────────────────────────────────────────class Game_Battler < Game_BattlerBase attr_accessor :threat #ALIAS - INITIALIZE alias euphoria_threat_gamebattler_initialize_15 initialize def initialize @threat = 0 euphoria_threat_gamebattler_initialize_15 end #ALIAS - DIE alias euphoria_threat_gamebattler_die_15 die def die @threat = 0 euphoria_threat_gamebattler_die_15 end #ALIAS - EXECUTE_DAMAGE alias euphoria_threat_gamebattler_executedamage_15 execute_damage def execute_damage(user) user.threat += skill_threat euphoria_threat_gamebattler_executedamage_15(user) end #NEW - SKILL_THREAT def skill_threat skill.threat_plus end #NEW - THREAT def threat threat = @threat end end#┌──────────────────────────────────────────────────────────────────────────────#│■ Window_Base#└──────────────────────────────────────────────────────────────────────────────class Window_Base < Window #NEW - DRAW_ACTOR_THREAT def draw_actor_threat(actor, x, y, width = 124) draw_gauge(x, y, width, actor.threat / 100.0, text_color(10), text_color(18)) change_color(system_color) draw_text(x, y, 45, line_height, "Threat") change_color(text_color(18)) draw_text(x + width - 42, y, 42, line_height, actor.threat.to_i, 2) end end#┌──────────────────────────────────────────────────────────────────────────────#│■ Window_BattleStatus#└──────────────────────────────────────────────────────────────────────────────class Window_BattleStatus < Window_Selectable #OVERWRITE - DRAW_GAUGE_AREA_WITHOUT_TP def draw_gauge_area_without_tp(rect, actor) draw_actor_hp(actor, rect.x + 0, rect.y, 72) draw_actor_mp(actor, rect.x + 82, rect.y, 64) draw_actor_threat(actor, rect.x + 156, rect.y, 64) end endNow the problem occurs with line 78. I get the error message "Undefined method or variable 'skill' for <Game_Enemy>".

    If anyone could tell me why this is and how to fix it, it would be greatly appreciated.

    The reason I find this so confusing and weird is because the error is in Game_Battler, Game_Enemy inherits from Game_Battler, and the error has to do with Game_Enemy.... wut?

    By the way, gauge works fine, everything looks good, but when I use a skill that's notetagged to modify @threat, it gives me the error.
  2. If it is an enemy that is trying to access `skill`, then it makes sense that it the error shows that a Game_Enemy object tried to call it.


    Where is `skill` defined?
  3. The error occurs when I use a skill that's tagged with <threat: x> as the player. Enemy attacks seem to be working fine.

    And I thought skill.threat_plus was just calling @threat_plus from RPG::Skill... I'm still relatively bad at scripting, so sorry if I'm not 100% sure how everything works :p

    I did try adding "attr_accessor :skill" to Game_Enemy, but that threw me another error, so I figured I was going the wrong way with that.

    Edit: Changed "RPG::Skill" to "RPG::UsableItem" and called the change in "@threat" from "make_damage_value" instead of "execute_damage" and it works now! Thanks to the advice of TheoAllen :)

    Also thank you Tsukihime for taking the time to reply, if you can tell me more about how the script knows where "item.threat_plus" comes from, I would like to know :D