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.

How to make a Window refresh?

Hello, all!

Let me preface this by saying that I have virtually no working knowledge of RGSS. I've done some some stuff, but it's been awhile, and I've pretty much forgotten everything.

Right, on to my question.

I have a window that occurs only when Switch 001 is "On". It works fine, but the problem is that it only checks to see if this switch is on upon entering or exiting the menu. At the least I need it to check upon entering or leaving a map, but I would prefer it to be constantly (a few frame interval is fine) checking to see whether or not Switch 001 is "On". Here is the code:

Code:
class Window_YourHUD < Window_Base
  attr_reader :hide#
  def initialize(act=0)
    @act = act
    @hide = -160 + @act*240#
    super(0, 0, 170, 130)
       self.back_opacity = 85
          if $game_switches[1] == false#
          self.x = -160#
        end#
                                 if $game_switches[1] == false#
                         self.x = @hide#
                         self.y = -128#
                         end#
    self.contents = Bitmap.new(width - 32, height  - 32)
  end
  end

Please forgive how sloppy it is. Like I said, the work of a beginner.

Thanks!

EDIT--

I remembered that I also had this in Scene_Map:

Code:
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end 
 
Shadowball, thanks! However, how do I do that?

I remembered that I also had this in Scene_Map:

Code:
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end 

Is it something wrong with that?
 

khmp

Sponsor

Include this method inside your window definition. Yeah definitely correct the tabbing. And I notice you have two if statements in your initialize that test the same thing. But they do two separate pieces of work. Like the below example:
Code:
if true
  x = 4
  y = 5
end
if true
  x = 3
end

Could you possibly in words or pictures describe what you are trying to with the window position wise. The code is kind of convoluted and hard to follow. Your aliasing in Scene_Map is fine though. We just need to create an update method for your hud window.

Code:
  def update
    if !$game_switches[1]
      self.x = @hide
      self.y = -128
    else
      self.x = self.y = 0
    end
  end

Just incorporate that into your class and it should update every frame and will move off screen when the switch goes off.
 
khmp, thanks! That was exactly what I was looking for!

I found what you were talking about concerning the redundant conditional branches. Here's what I fixed it to:

Code:
if $game_switches[1] == false
          self.x = -160
          self.x = @hide
          self.y = -128
        end

Easy enough. Clearly I wrote little bits and pieces as I learned, so the whole thing isn't very cohesive. However, it now does exactly what I need. Thanks again!
 

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