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.

aliasing problem

Hi im having a problem with using a aliasing that goes into Scene_Map and updateing, heres the script:
Code:
class Window_Skills < Window_Base
  def initialize
    super(0,0,200,200)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 150, 32, "Attack:")
    self.contents.draw_text(70, 0, 150, 32, "1")
    self.contents.draw_text(0, 20, 150, 32, "Strength:")
    self.contents.draw_text(70, 20, 150, 32, "1")
    self.contents.draw_text(0, 40, 150, 32, "Defense:")
    self.contents.draw_text(70, 40, 150, 32, "1")
end
def update
  refresh
end
end
class Scene_Map
alias old_main main
alias old_update update
  def main
    old_main
    @window = Window_Skills.new
  end
  def dispose
    @window.dispose
  end
  def update
    old_update
    @window.update
  end
end
It's probably a really simple error but i can't see it! Just recently bought Ruby Pocket reference, but i cant see what i wcould be doing wrong.

The Error says:
Script 'My_Window'line 33: NoMethodError occurred.
undefined method 'update' for nil:NilClass

Appreciate the help!
 

khmp

Sponsor

NM I see the update method definition.

I think I got it. When you alias main there's a tiny problem. There's a loop in it. The code for when the window is created is never reached until that loop is broken. So just place @window = Window_Skills.new above old_main.

So now it should be
Code:
class Scene_Map
alias old_main main
alias old_update update
  def main
    @window = Window_Skills.new
    old_main
  end
  def dispose
    @window.dispose
  end
  def update
    old_update
    @window.update
  end
end
 

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