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.

Undefined method 'font'

Hello!

When I run the code below I get an undefined method 'font' when it hits the line:

self.contents.font.color = disabled_color

I've been using Window_Skill as a reference and it has no problem with it, so can anyone help me with what might be the problem? It's probably something simple... >.<

Code:
class Window_SetSkills < Window_Selectable
  
  def initialize
    super(128, 64, 512, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    
    @columns = 2
    refresh
    self.index = 0
  end
  
  #DEFINE skill
 # def skill
 #   return @data[self.index]
 # end
  
  #DEFINE refresh
  def refresh
    
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    
    @numofskills = $game_skillset.size
    if @numofskills > 0
      for i in 0...@numofskills
        draw_skillset(i)
      end
    end  
  #end definition
  end
  
  #Define draw_skillset, index is the position of the current skill in array
  def draw_skillset(index)
    skill = $game_skillset[index]
    
    #Gray out if Hero already knows
    if $game_party.actors[0].skill_learn?(skill.id)
      self.contents.font.color = disabled_color
    else
      self.contents.font.color = normal_color
    end
    
    if (index % 2) == 0 #Even, left column
      cx = contents.text_size(skill.name).width
      self.contents.draw_text(0, (index / 2) * 32, cx, 32, skill.name, 0)
    else #Odd, right column
      cx = contents.text_size(skill.name).width
      self.contents.draw_text(258, (index / 2 ) * 32, cx, 32, skill.name, 0)  
    end
  #end definition
  end
  
  #Define update_helpinfo
  def update_helpinfo
    @window_help.set_text(self.skill == nil ? "" : self.skill.description)
  end
  
   
#end of class
end

Tried searching to see if anyone had already asked something similar but I didn't see anything so far, so figured I'd ask. Thanks for any help.
 
Code:
def refresh
    
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    
    @numofskills = $game_skillset.size
    if @numofskills > 0
      for i in 0...@numofskills
        draw_skillset(i)
      end
    end  
  #end definition
  end

You aren't redefining self.contents after this. Despite what you are saying, you aren't getting a "font" method not found error, you're getting a "font method not found for nilClass" error, because self.contents is Nil, rather than a Bitmap object like it should be.

What you likely want to do is redefine self.contents after clearing it, and determining the number of skills. Although you are writing some unnecessary code around that area anyways so let me clean it up for you.

Code:
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    if $game_skillset.size > 0
      self.contents = Bitmap.new(width - 32, $game_skillset.size * 32)
      for i in 0...$game_skillset.size
        draw_skillset(i)
      end
    end
  end
 
Awesome! That fixes it. :)

I had been wondering about the bitmap stuff I've been seeing but hadn't gotten around to learning what it does yet. Thanks for the help!
 

khmp

Sponsor

As more of a "for your information". You can just clear the draw surface rather than recreating it every refresh.
Code:
  self.contents.clear
in place of:
Code:
  if self.contents != nil
    self.contents.dispose
    self.contents = nil
  end

And then again in your Refresh method:
Code:
  if $game_skillset.size > 0
    for i in 0...$game_skillset.size
      draw_skillset(i)
    end
  end
in place of:
Code:
  if $game_skillset.size > 0
    self.contents = Bitmap.new(width - 32, $game_skillset.size * 32)
    for i in 0...$game_skillset.size
      draw_skillset(i)
    end
  end

Good luck with it Naiamod! :thumb:
 

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