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.

A little help -- disposed window

Aran

Member

Here's a small script I made, but I get an error for 'dispose window'

Code:
#==============================================================================
# ** Time Display
#==============================================================================
# Aran
# Version 1.0
# 03.07.06
#==============================================================================
#Via the Advanced Time System (Required) you can display the time on your screen
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Time Display", "Aran", 1, "03.07.06")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Time Display") == true
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# * Time HUD
#------------------------------------------------------------------------------
  class Window_Time < Window_Base
    def initialize
      super(width - 640, 430, self.contents.width, 50)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = 0
      self.contents.font.name = "Goudy Old Style"
      refresh
    end
    
    def refresh
      self.contents.clear
      draw_text(4,4,160,28,"Time:" + $ats.clock)
    end
    
    def update
      refresh
    end
  end
  
#==============================================================================
# * Scene Map
#------------------------------------------------------------------------------  
  class Scene_Map
    
#------------------------------------------------------------------------------
# * Alias Listings
#------------------------------------------------------------------------------
    alias aran_time_disp_scn_map_main main
    alias aran_time_disp_scn_map_update update
#------------------------------------------------------------------------------    
    
    def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
    end
    
    def update
      @win_time.update
      if $scene != self
        @win_time.dispose
      end
            aran_time_disp_scn_map_update
    end
  end
  
#------------------------------------------------------------------------------
# * End SDK Test
#------------------------------------------------------------------------------
end
 
Try instead of:
Code:
 def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
    end
    
   def update
      @win_time.update
      if $scene != self
        @win_time.dispose
      end
            aran_time_disp_scn_map_update
    end

this one:
Code:
 def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
      @win_time.dispose
    end
    
    def update
      @win_time.update
      aran_time_disp_scn_map_update
    end
 
The window is disposed at the end of the original main method. Here we have our original main method:
Code:
  def main
    # Make sprite set
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
  end

So technically we only did this by aliasing it:
Code:
def main
    [color=red]@win_time = Window_Time.new[/color]
    # Make sprite set
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
    [color=red]@win_time.dispose[/color]
  end
 

Aran

Member

I'm not really following -^^-D *rubs head*

What's the moral of this story?

EDIT: What do you do about windows when you go to another scene?

I tried:

Code:
class Scene_Map

alias whatever update

def update
blah, blah...
if $scene != self
@window.dispose #and yes I have 'window' instance-variabled in main method
end
end
 
It's the same thing as the window is disposed at the end of the main method, if changing maps or scenes.
since you didn't understand it, in easier steps. ^^
We have our original main method:
Code:
[color=blue]def main
    # Make sprite set
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
  end[/color]

Now we want to add something in the main methodso we're aliasing it.
Code:
[color=blue]alias aran_time_disp_scn_map_main[/color] main

Now the main method above is named aran_time_disp_scn_map_main.
We now create a new main method:
Code:
[color=red]def main
@win_time = Window_Time.new
end[/color]

Now we also want to include the original main method we had before, so we call it.
Code:
[color=red]def main
@win_time = Window_Time.new[/color]
[color=blue]aran_time_disp_scn_map_main[/color]
[color=red]end[/color]

So we technically have
Code:
[color=red]def main
    @win_time = Window_Time.new[/color]
    [color=blue]# Make sprite set
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end[/color]
  [color=red]end[/color]

We know now, we can dispose a window at the end of a main method. As we can't include within the original main method without rewriting it, we still can add it at the end.

Code:
[color=red]def main
    @win_time = Window_Time.new[/color]
    [color=blue]# Make sprite set
    @spriteset = Spriteset_Map.new
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end[/color]
  [color=red]@win_time.dispose
end[/color]

Now we don't need to write everything as we have named the original main method before, so we only need to call it. And so we have:
Code:
[color=red]def main
    @win_time = Window_Time.new[/color]
    [color=blue]aran_time_disp_scn_map_main[/color]
  [color=red]@win_time.dispose
end[/color]

You don't need to add it to the update method as it checks the main method anyway, when you call the original method but it won't dispose @win_time, because you haven't added it. hope this helps, if you have some questions, just ask.
 

Aran

Member

h/o, wait... so I should have the main method executed in update?

I mean, I understand all the aliasing and stuff; I knew what I was doing there. But I just don't understand disposing a window because that's what you need to happen before you can go to another scene, correct? Is that ALL that needs to happen before you go to another scene?
 

Aran

Member

I did.

Here's the script:

Code:
#==============================================================================
# ** Time Display
#==============================================================================
# Aran
# Version 1.0
# 03.07.06
#==============================================================================
#Via the Advanced Time System (Required) you can display the time on your screen
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Time Display", "Aran", 1, "03.07.06")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Time Display") == true
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# * Time HUD
#------------------------------------------------------------------------------
  class Window_Time < Window_Base
    
    attr_accessor :left_rite_pos
    
    def initialize
      super(0, 380, 160, 110)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = 0
      self.contents.font.name = "Goudy Old Style"
      refresh
    end
        
    def refresh
      self.contents.clear
      self.contents.draw_text(4, 0, 120, 32, "Time: " + $ats.clock)
      self.contents.draw_text(4, 16, 120, 32, "Weather: " + $ats.weather_is)
      self.contents.draw_text(4, 32, 120, 32, "Date: " + $ats.date)
      self.contents.draw_text(4, 48, 120, 32, "Season: " + $ats.season)
    end
    
    def update
      refresh
    end
  end
  
#==============================================================================
# * Scene Map
#------------------------------------------------------------------------------  
  class Scene_Map
    
#------------------------------------------------------------------------------
# * Alias Listings
#------------------------------------------------------------------------------
    alias aran_time_disp_scn_map_main main
    alias aran_time_disp_scn_map_update update
#------------------------------------------------------------------------------    
    
    def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
      @win_time.dispose
    end
    
    def update
      @win_time.update
      aran_time_disp_scn_map_update
    end
  
  end
  
#------------------------------------------------------------------------------
# * End SDK Test
#------------------------------------------------------------------------------
end
 
You shouldn't call the refresh method of a window every frame especially since it uses the draw_text method because it will cause lag. here is a fix for that

Code:
#------------------------------------------------------------------------------
# * Time HUD
#------------------------------------------------------------------------------
  class Window_Time < Window_Base
    
    attr_accessor :left_rite_pos
    
    def initialize
      super(0, 380, 160, 110)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = 0
      self.contents.font.name = "Goudy Old Style"
      refresh
    end
        
    def refresh
      @old_clock = $ats.clock
      @old_weather = $ats.weather_is
      @old_date = $ats.date
      @old_season = $ats.season
      self.contents.clear
      self.contents.draw_text(4, 0, 120, 32, "Time: " + $ats.clock)
      self.contents.draw_text(4, 16, 120, 32, "Weather: " + $ats.weather_is)
      self.contents.draw_text(4, 32, 120, 32, "Date: " + $ats.date)
      self.contents.draw_text(4, 48, 120, 32, "Season: " + $ats.season)
    end
    
    def update
      if @old_clock != $ats.clock and @old_weather != $ats.weather_is and @old_date != $ats.date and @old_season != $ats.season
        refresh
      end
    end
  end
 
Aran said:
I did.

Here's the script:

Code:
#==============================================================================
# ** Time Display
#==============================================================================
# Aran
# Version 1.0
# 03.07.06
#==============================================================================
#Via the Advanced Time System (Required) you can display the time on your screen
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Time Display", "Aran", 1, "03.07.06")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Time Display") == true
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# * Time HUD
#------------------------------------------------------------------------------
  class Window_Time < Window_Base
    
    attr_accessor :left_rite_pos
    
    def initialize
      super(0, 380, 160, 110)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = 0
      self.contents.font.name = "Goudy Old Style"
      refresh
    end
        
    def refresh
      self.contents.clear
      self.contents.draw_text(4, 0, 120, 32, "Time: " + $ats.clock)
      self.contents.draw_text(4, 16, 120, 32, "Weather: " + $ats.weather_is)
      self.contents.draw_text(4, 32, 120, 32, "Date: " + $ats.date)
      self.contents.draw_text(4, 48, 120, 32, "Season: " + $ats.season)
    end
    
    def update
      refresh
    end
  end
  
#==============================================================================
# * Scene Map
#------------------------------------------------------------------------------  
  class Scene_Map
    
#------------------------------------------------------------------------------
# * Alias Listings
#------------------------------------------------------------------------------
    alias aran_time_disp_scn_map_main main
    alias aran_time_disp_scn_map_update update
#------------------------------------------------------------------------------    
    
    def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
      @win_time.dispose
    end
    
    def update
      @win_time.update
      aran_time_disp_scn_map_update
    end
  
  end
  
#------------------------------------------------------------------------------
# * End SDK Test
#------------------------------------------------------------------------------
end

Okay, good, but did you understand it? That's what you were asking for, wasn't it? I already told you in the first post i posted how to fix that.
 

Aran

Member

Hmm... its still not fixed tho -_-. Aww... this stinks. This was going to be my first full-proof script too...

And Yes, I understood it.

@trickster: Is the clock ever going to update now? When will the clock time ever match the old times again?
 

Aran

Member

No, no it works but not fully. I still have to be able to go to different scenes, but it can't do that because I get an error in Window_Base for disposed window. And its pissing me off b/c I HAVE DISPOSED THE WINDOW!!!

*eyes blaze*

I just don't get it -_-.

The biggest problem that I'm having is that its my first script and this minor problem is keeping me from releasing it. But once again, as with many of my other attempts its just some tiny little embarassing thing I missed (most likely)
 
Lol trickster that way the window will show the next second only after all the data changes (season, weather, time and date at the same time). Making it update only in a different time won´t reduce the lag too bcoz this timer is updated and changed on each frame. I found a better way, maybe... Just show the hours and minutes, and let the seconds out:
Code:
#==============================================================================
# ** Time Display
#==============================================================================
# Aran
# Version 1.0
# 03.07.06
#==============================================================================
#Via the Advanced Time System (Required) you can display the time on your screen
#==============================================================================


#------------------------------------------------------------------------------
# * Time HUD
#------------------------------------------------------------------------------
  class Window_Time < Window_Base
    
    attr_accessor :left_rite_pos
    
    def initialize
      super(0, 380, 160, 110)
      self.contents = Bitmap.new(width - 32, height - 32)
      self.opacity = 0
      self.contents.font.name = "Arial"
      refresh
    end
        
    def refresh
      @old_clock = make_clock
      self.contents.clear
      self.contents.draw_text(4, 0, 120, 32, "Time: " + @old_clock)
      self.contents.draw_text(4, 16, 120, 32, "Weather: " + $ats.weather_is)
      self.contents.draw_text(4, 32, 120, 32, "Date: " + $ats.date)
      self.contents.draw_text(4, 48, 120, 32, "Season: " + $ats.season)
    end
    
    def make_clock
      clock = $ats.clock
      clock.sub(/\:.*\d/,sprintf(":%02d", $ats.min_is))
    end
    
    def update
      if @old_clock != make_clock
        refresh
      end
    end
  end  
#==============================================================================
# * Scene Map
#------------------------------------------------------------------------------  
  class Scene_Map
    
#------------------------------------------------------------------------------
# * Alias Listings
#------------------------------------------------------------------------------
    alias aran_time_disp_scn_map_main main
    alias aran_time_disp_scn_map_update update
#------------------------------------------------------------------------------    
    
    def main
      @win_time = Window_Time.new
      aran_time_disp_scn_map_main
      @win_time.dispose
    end
    
    def update
      @win_time.update
      aran_time_disp_scn_map_update
    end
  
  end

Sorry i had to change the font and take out the SDK enslavement (yes! >=Y).

BTW there´s no problem with your script anyways. Everything is just nicely done, except for that refresh thing. And i don´t really suggest you to make a window that redraws its contents in so small time in a map. You´ll get lag problems easier. It´s better to make that inside a menu.
 

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