MV Close a window that was created through script calls.

I read through this thread and figured out how to create a window with script calls.
https://forums.rpgmakerweb.com/inde...m-windows-in-events-using-script-calls.62932/
But no one said how to close this window. In fact there are people asking how to close it like me.

This is what my script call looks like.
var width = Graphics.boxWidth - 50; var win = new Window_Base(25, Graphics.boxHeight - 140, width, 90); //x,y,width,height SceneManager._scene.addChild(win) //adds the window to the curent scene win.drawText("Sprig", -25, 0, width, "center"); //draws the text
Then after a wait of 90 frames, I need it to close.
what exactly do you want to make?
if you just want a short text to show up, why not using a variable text
on screen or a gab window?

its better to explain what you want to do, so we can take steps from there.
I just want a small message box to appear on the screen with whatever I want to write in there, then make it close.

The reason why it needs to be different from the normal text box is because it needs to be smaller.
for what does the window needs? for MapName, chest popup?
other reasons?

as there are some plugins and timed message bubble that goes away
by a set of time, same for popups for any text (the length is automatically
adjusted by that.
but if you want to close it, you could try to add the follow 2 lines to it:

this.wait(90) // waits 90 frames
win.close();

now just becarefull as win.close could close the game when used alone.
so you might want to change win to a different name to avoid that,
but test to see if it works.
Well it closes, but the wait doesn't actually stop it from closing instantly.
I thought to separate them. Create window Script Call, wait 90 frames, then close Script Call. But this would give me a undefined window error.

And to answer your question, the window just needs to show text in a smaller textbox which pauses the player. That's it.
var width = Graphics.boxWidth - 50; var win = new Window_Base(25, Graphics.boxHeight - 140, width, 90); //x,y,width,height SceneManager._scene.addChild(win) //adds the window to the curent scene win.drawText("Sprig", -25, 0, width, "center"); //draws the text

Your code is technically correct; however, we usually do something like this just to cover your requirements.

Code:
var width = Graphics.boxWidth - 50;
SceneManager._scene._myCustomWindow = new Window_Base(25, Graphics.boxHeight - 140, width, 90); //x,y,width,height
SceneManager._scene.addChild(SceneManager._scene._myCustomWindow) //adds the window to the curent scene
SceneManager._scene._myCustomWindow.drawText("Sprig", -25, 0, width, "center"); //draws the text

This way, you can easily call anytime SceneManager._scene._myCustomWindow.close()
I thought to separate them. Create window Script Call, wait 90 frames, then close Script Call. But this would give me a undefined window error.
That's because the variable you're declaring is only available in the scope of its script call. You can make it available globally by doing window.customMessage=win in the first one, and let win = window.customMessage anywhere you want to use it.

EDIT: Got ninja'd by Aerosys - his way will also work fine, and is a bit neater by not creating a global variable.

Also, if you want to fully delete a window and not just close it, this is a bit more memory friendly:
JavaScript:
win.contents.clear();
win.close();
SceneManager._scene.removeChild(win);
Aerosys' way works perfectly! Thank you! Also thank you Mac for telling me about deleting it.

Original thread: https://forums.rpgmakerweb.com/threads/close-a-window-that-was-created-through-script-calls.162899/