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.

"Set Visibility" Window Method

Status
Not open for further replies.
For my CMS, I've been making window classes that function from within one another. For example, my skill window class contains two window classes: one to display the skills on one half of the screen, and another to display the selected skill's statistics on the other half of the screen.

I have it set up so that I only need to declare the main skill window in order for both to appear (and likewise with disposing). However, I'm having trouble making 'set visible' and 'set active' to work properly.

For proper disposal, I use this code.
Code:
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    @helper_window1.dispose
    @helper_window2.dispose
    super
  end
The helper windows are declared on initialization, and this destroys them on disposal. Works perfectly. However, the following code is what is giving me headaches.

Code:
  #--------------------------------------------------------------------------
  # * Set Visibility
  #     visibility : state of window visibility (boolean)
  #--------------------------------------------------------------------------
  def visible=(visibility)
    @helper_window1.visible = visibility
    @helper_window2.visible = visibility
    self.visible = visibility
  end
I understand why this code doesn't work. Basically, by calling "self.visible = visibility" inside the function, I'm creating an endless recursion. The only solution I have come up with is to use the following code.
Code:
  #--------------------------------------------------------------------------
  # * Set Visibility
  #     visibility : state of window visibility (boolean)
  #--------------------------------------------------------------------------
  def set_visibility(visibility)
    @helper_window1.visible = visibility
    @helper_window2.visible = visibility
    self.visible = visibility
  end
However, I consider this rather messy. I have to go through all instances of setting the skill window's visibility and call this "set_visibility" function, instead.

Is this the only option? Or might Ruby have some nifty solution (like it normally does :))?
 
Status
Not open for further replies.

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