Disposing of a custom window

So, I have a problem which is probably easy to solve, but I can't figure out since I am completely new to scripting:


I wanted to display a window with a message which didn't disappear despite user input, so I added this script:


class Window_Bro < Window_Base
def initialize
super(Graphics.width / 4, 0, Graphics.width / 2, 48)
refresh
end

def refresh
if $game_variables[78] == 1
draw_text( 0, 0, contents_width, contents_height, "Nessa")
else if $game_variables[78] == 2
draw_text( 0, 0, contents_width, contents_height, "Alice", 1)
else
draw_text( 0, 0, contents_width, contents_height, "Liu", 1)
end

end
end
end


I use a script call in-game for when I need it: (@w=Window_Bro.new) but when it comes to make it disappear, I haven't found a way to do it. That also means that calling the window again creates a "stack" of window, with the different text overlapping. So how would I go about deleting and/or refreshing the content of the window?


Edit: Forgot to mention I am using RPG Maker VX Ace.
Using a script call to make windows directly there is a bad idea.


That means that the window will be created in the event's interpreter (which is an instance of the Game_Interpreter class).


You can lose the reference to these windows easily this way, and that means you won't be able to get rid of them.


If the player doesn't need to move when this window is shown, you could do this:

Spoiler
@mwin = Window_Bro.new
Fiber.yield until Input.trigger?🙂C) || Input.trigger?🙂😎
Sound.play_ok
@mwin.dispose

This will create the window, wait for player input (confirm or cancel button pressed), and disposes the window after that.


This is also safe to do, because you are disposing it in the same interpreter instance you created it.


If you want to allow player movement when the window is shown, you should create the window in the scene itself, and make a script call to trigger the window there instead.


You will still need to maintain a disposal logic (in case there is already a shown window when a new one is triggered, you will need to dispose the old one before making another), but your window will be an a class where you can always access it without the fear of losing the reference to it.


If you need to update the content of the window in real time, you will have to add your refresh method into the window's update method, and you will need to make a condition for it, so that it only draws the data when it really needs to (otherwise it will impact performance way more than it should).
Is it really impossible to delete a window after you create it in the event's interpreter?


Anyway, I think I can do it by modifying your example a little (although in the future I might have to make the window in the scene, since I might want the player to be able to move), thank you very much for your help! 😀

Original thread: https://forums.rpgmakerweb.com/threads/disposing-of-a-custom-window.71826/