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.

Remove window?

Hi,

i'm very new to scripting and i reccently made my first window. Here is the script:

Code:
class Window_First < Window_Base
  #------------------------------------------------#
  # Object Initialization                                         #                
  #------------------------------------------------#
  def initialize
    super(0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    
    refresh
  end
  
  #------------------------------------------------#
  # Refresh                                                        #
  #------------------------------------------------#
  def refresh
    self.contents.clear

    self.contents.draw_text(0, 0, 256, 32, "Hello, World", 1)
 end
end


And my question is, how can you make it so when the person playing the game can remove the window by pressing a button, lets say C?  I belive it has something to do with $window.dispose but i can't quite figure it out >.<
Thx.

//Gando
 

khmp

Sponsor

As good scripting practice I tell everyone to have the scene handle input and tell the objects of said scene to react based on that input. So it depends upon the scene you place this in. I'll make a quick example here using Scene_Map.

Code:
class Scene_Map
  #
  # Make sure to alias the methods we need to alter, as to not override them.
  #
  alias_method :gand_firstwindow_main, :main
  alias_method :gand_firstwindow_update, :update
  #------------------------------------------------------------------------
  # * Main Processing
  #------------------------------------------------------------------------
  def main
    # Create an instance of our window.
    @w_firstwindow = Window_First.new

    # Make sure to call Scene_Map::main's original code.
    gand_firstwindow_main

    # Dispose of the instance of our window.
    @w_firstwindow.dispose
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # If the user presses the X button toggle the window's visibility.
    if Input.trigger?(Input::X)
      @w_firstwindow.visible = !@w_firstwindow.visible
    end
  end
end

Now if you just wanted the window to disappear completely.

Code:
class Scene_Map
  #
  # Make sure to alias the methods we need to alter, as to not override them.
  #
  alias_method :gand_firstwindow_main, :main
  alias_method :gand_firstwindow_update, :update
  #------------------------------------------------------------------------
  # * Main Processing
  #------------------------------------------------------------------------
  def main
    # Create an instance of our window.
    @w_firstwindow = Window_First.new

    # Make sure to call Scene_Map::main's original code.
    gand_firstwindow_main

    # Dispose of the instance of our window.
    @w_firstwindow.dispose unless @w_firstwindow.disposed?
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # Remove the window if the user presses X and it hasn't already been removed.
    if Input.trigger?(Input::X)
      @w_firstwindow.dispose unless @w_firstwindow.disposed?
    end
  end
end

Good luck with scripting Gando! :thumb:

Also in the draw_text method call of your window. You can simply apply the method "width" in place of 256.
 
khmp":22vqbuol said:
As good scripting practice I tell everyone to have the scene handle input and tell the objects of said scene to react based on that input. So it depends upon the scene you place this in. I'll make a quick example here using Scene_Map.

Code:
class Scene_Map
  #
  # Make sure to alias the methods we need to alter, as to not override them.
  #
  alias_method :gand_firstwindow_main, :main
  alias_method :gand_firstwindow_update, :update
  #------------------------------------------------------------------------
  # * Main Processing
  #------------------------------------------------------------------------
  def main
    # Create an instance of our window.
    @w_firstwindow = Window_First.new

    # Make sure to call Scene_Map::main's original code.
    gand_firstwindow_main

    # Dispose of the instance of our window.
    @w_firstwindow.dispose
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # If the user presses the X button toggle the window's visibility.
    if Input.trigger?(Input::X)
      @w_firstwindow.visible = !@w_firstwindow.visible
    end
  end
end

Now if you just wanted the window to disappear completely.

Code:
class Scene_Map
  #
  # Make sure to alias the methods we need to alter, as to not override them.
  #
  alias_method :gand_firstwindow_main, :main
  alias_method :gand_firstwindow_update, :update
  #------------------------------------------------------------------------
  # * Main Processing
  #------------------------------------------------------------------------
  def main
    # Create an instance of our window.
    @w_firstwindow = Window_First.new

    # Make sure to call Scene_Map::main's original code.
    gand_firstwindow_main

    # Dispose of the instance of our window.
    @w_firstwindow.dispose unless @w_firstwindow.disposed?
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # Remove the window if the user presses X and it hasn't already been removed.
    if Input.trigger?(Input::X)
      @w_firstwindow.dispose unless @w_firstwindow.disposed?
    end
  end
end

Good luck with scripting Gando! :thumb:

Also in the draw_text method call of your window. You can simply apply the method "width" in place of 256.





Thx for the reply khmp!  :smile:  altough i don't really understand what you mean, i feel like such a noob :dead: :tongue2:
Should i paste it after my original script or what? like this:

Code:
class Window_First < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    
    refresh
  end
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    
  if $game_switches[1]
    self.contents.draw_text(0, 0, 256, 32, "Hello, World")
  else
    self.contents.draw_text(0, 0, 256, 32, "Wazzaaaaap!?", 2)
  end
 end
end

class Scene_Map
  #
  # Make sure to alias the methods we need to alter, as to not override them.
  #
  alias_method :gand_firstwindow_main, :main
  alias_method :gand_firstwindow_update, :update
  #------------------------------------------------------------------------
  # * Main Processing
  #------------------------------------------------------------------------
  def main
    # Create an instance of our window.
    @w_firstwindow = Window_First.new

    # Make sure to call Scene_Map::main's original code.
    gand_firstwindow_main

    # Dispose of the instance of our window.
    @w_firstwindow.dispose unless @w_firstwindow.disposed?
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # Remove the window if the user presses X and it hasn't already been removed.
    if Input.trigger?(Input::X)
      @w_firstwindow.dispose unless @w_firstwindow.disposed?
    end
  end
end

cuz when i do, i get an error on this line:

Code:
alias_method :gand_firstwindow_main, :main

the error message says:  Undefined method `main' for class `Scene_Map'


Well, thanks again^^ :tongue2:
 

khmp

Sponsor

Don't feel like a newbie. We've all been where you have been. I still make stupid mistakes that would be able to catch that I overlook. Anyway as for the problem. Mostly every code snippet I do is to be inserted into an empty section above main in the script listings. The problem most likely lies in that this code is most likely defined above the default Scene_Map file. Put this entire script into a section directly above main in the script listings. Look in the RGSS FAQ for a more in depth walkthrough for installing scripts.

So resolution for this would be make sure you restore Scene_Map to its original state. By copying an unedited version from a different project. Then insert an empty section above main in the script listings and paste the code, I gave you, in it.

Good luck with it Gando! :thumb:
 
khmp":ocrtxfha said:
Don't feel like a newbie. We've all been where you have been. I still make stupid mistakes that would be able to catch that I overlook. Anyway as for the problem. Mostly every code snippet I do is to be inserted into an empty section above main in the script listings. The problem most likely lies in that this code is most likely defined above the default Scene_Map file. Put this entire script into a section directly above main in the script listings. Look in the RGSS FAQ for a more in depth walkthrough for installing scripts.

So resolution for this would be make sure you restore Scene_Map to its original state. By copying an unedited version from a different project. Then insert an empty section above main in the script listings and paste the code, I gave you, in it.

Good luck with it Gando! :thumb:

Thanks for all the help khmp! I really appreciate it! :smile:
the problem was, as you said that the script was placed above Scene_Map, ^^
now i've placed it above Main and now it works, BUT..
I can't move the character when i start the game. You can see the map, and you can remove the window, but you can't enter the menu  or move the character or anything, just like when you have an event on autorun.

I would like for it to be a window that you can call, and then when the player is done reading what it says he can press the button and keep on playing. :neutral:

Once again, thanks for the help! :wink:
 

khmp

Sponsor

See I made a mistake already.  :lol:

The problem is that the update's old code, that's the method we aliased at the top, is never actually being called in the update method we made. To remedy this replace the custom Scene_Map update with this:
Code:
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # If the user presses the X button toggle the window's visibility.
    if Input.trigger?(Input::X)
      @w_firstwindow.visible = !@w_firstwindow.visible
    end

    # Call the old update code.
    gand_firstwindow_update
  end

Sorry for missing that.

Good luck with it Gando! :thumb:

If you have any other questions about it or the syntax just ask.

[edit]Oops I missed what you were asking for. I'll do some testing this time and get back to you on it.[/edit]

Okay. First for you to have the text "Press any key to continue", insinuates that ANY key could be pressed. The input module doesn't have a condition for this built in. You'll need an input script for it. Unless you want to use the something like "Press the Action button to continue". Then this becomes a lot simpler.

Here's my idea for the can't move while this window is visible.

Create a sprite with a bitmap which will hold the text for press anything to continue message. In the update if the window is visible. Do not allow the old code to be executed and just display the window and the sprite drawing the text. If that's what you want just let me know.
 
khmp":1auahvwx said:
See I made a mistake already.  :lol:

The problem is that the update's old code, that's the method we aliased at the top, is never actually being called in the update method we made. To remedy this replace the custom Scene_Map update with this:
Code:
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # If the user presses the X button toggle the window's visibility.
    if Input.trigger?(Input::X)
      @w_firstwindow.visible = !@w_firstwindow.visible
    end

    # Call the old update code.
    gand_firstwindow_update
  end

Sorry for missing that.

Good luck with it Gando! :thumb:

If you have any other questions about it or the syntax just ask.

[edit]Oops I missed what you were asking for. I'll do some testing this time and get back to you on it.[/edit]


Mwahaha ^^ :wink:
Yaaaay, now i can move the character, *jumps up and down* xD
Okaay, thanks for all the help!  :smile:

i think i'm starting to understand this a little bit better now..  but i have 2 questions, probably 2 stupid questions o.O

What is @w, and what does this scentence do?:

Code:
@w_firstwindow = Window_First.new

what is gand? :

Code:
gand_firstwindow_main
 

khmp

Sponsor

First question what is the @w_. While coding I apply a very liberal amount of hungarian notation. I think that's what it was called anyway. Variables are prefixed by a short blurb that makes variable discernment easier. The w_ is my of saying the variable is a window. The "@" denotes that the variable scope is a public instance variable. Meaning the variable can be accessed anywhere from within the class in which it is contained. I hope I didn't geek out too much there but if want to know more check out the Ruby tutorial section.

Next what is gand. When I first started here I just used to have something like this when using alias_method:
Code:
alias_method :old_update, :update
What I learned from SephirothSpawn is that when SDK logs an alias_method it isn't helpful if you have 18 scripts that alias a method and they all share the same the aliasing name. So to make it unique to a script we include first the four letters of the user that created it. In this case I shortened "Gando" to "gand". The script name which I made up "firstwindow" and then the method we are aliasing is the last part. But honestly this information is irrelevant if you aren't using the SDK. Its something I do out of habit rather than necessity.
 

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