Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Enemy HP

Hi me again I've been having problems with Enemy HP
i forgot where i got this but my problem is
when i use skill that can heal during the game
enemy hp line 327: NameError occurred
it says undefined local variable or method 'hp_x' for
#<window_help:0X3845800>

Code:
#==============================================================================
# 本脚本æ
 

khmp

Sponsor

The only problem seems to be a copy and paste error. They made the hp method above the sp one then copied and pasted the method but didn't change all of the local variable names. Here's the method:
Code:
  alias draw_actor_sp_original draw_actor_sp
  def draw_actor_sp(actor, x, y, width = 144)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      sp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      sp_x = x + width - 48
      flag = false
    end
    # Draw Shadow Effects for Battles
    if $scene.is_a?(Scene_Battle)
      self.contents.font.color = Color.new(0, 0, 0, 192)
      self.contents.draw_text(x, y+1, 32, 32, $data_system.words.sp)
      self.contents.draw_text(x+1, y, 32, 32, $data_system.words.sp)
      self.contents.draw_text(sp_x, y+1, 48, 32, actor.sp.to_s, 2)
      self.contents.draw_text(sp_x+1, y, 48, 32, actor.sp.to_s, 2)
      if flag
        self.contents.draw_text(sp_x + 49, y, 12, 32, "/", 1)
        self.contents.draw_text(sp_x + 48, y+1, 12, 32, "/", 1)
        self.contents.draw_text(sp_x + 60, y+1, 48, 32, actor.maxsp.to_s)
        self.contents.draw_text(sp_x + 61, y, 48, 32, actor.maxsp.to_s)
      end
    end
    # Draw "SP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    # Draw SP
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
    # Draw MaxSP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
    end
  end

And here's the whole thing with the method fixed:
Code:
#==============================================================================
# 本脚本æ
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top