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.

[Resolved] Problem Displaying New Element Resistance

Culex

Member

In Window_Base, I have created a definition called 'draw_actor_resistance.'

For now, its sole purpose is to display the value of the character's resistance to a certain element, based on the table in Game_Actor:

Code:
table = [0,200,150,100,50,0,-100]

But it's not working. Here is the error I get.

Code:
Script 'Window_Base' line 333: NoMethodError occured.
undefined method 'element_rate' for nil:NilClass

Here is the script I am currently working in Window_Base, where the error occurs:

Code:
def draw_actor_resistance(actor, x, y, element)
    case element
    when 0
      element_resist = $game_actor.element_rate(0)
    end
    self.contents.font.color = normal_color
    self.contents.draw_text(x, y, 36, 32, element_resist.to_s, 2)
end

Here is the part of class Game_Actor where I get ".element_rate" from:
Code:
#-------------------------------------------------------------------------
# * Get Element Revision Value
#     element_id : element ID
#-----------------------------------------------------------------------
  def element_rate(element_id)
    # Get values corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    result = table[$data_classes[@class_id].element_ranks[element_id]]
    # If this element is protected by armor, then it's reduced by half
    for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
      armor = $data_armors[i]
      if armor != nil and armor.guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # If this element is protected by states, then it's reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # End Method
    return result
  end

If my method is undefined, how will I define the actor's rate of elemental resistance based on the table in Game_Actor? If this doesn't make sense, I will try to clarify my problem further. Thank you in advance.
 

Culex

Member

Huzzah! To think a simple typo halted my success! I modified it from there to draw a shield if the character's resistance is less than or equal to 50 in the database. At last, I can rest...for a while. Thank you, Mr. Mo!

This topic is RESOLVED.
 

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