MZ Cannot readd property of close.

I think I am coming close to finishing a code I've been working on. Issue is, I keep getting an error message that says that the property cannot be readd. I am coding an invisible window that opens on the players screen for a few seconds and then closes.

Code:
◆Script:let myWindow;
:      :const options = {transparent:true,frame:false,};
:      :var newWin=null;
:      :  myWindow = nw.Window.open("Cute.html", options, function(win){newWin = win; win.moveTo(300,400);});
:      :setTimeout(() => {
:      :            function closeWin() {
:      :    if(myWindow){
:      :        myWindow.close();
:      :    }
:      :}
:      :}, 5000);
:      :
:      :
:      :
Screenshot 2025-01-31 223909.png
This error message basically tells you that "myWindow" is undefined, which means myWindow does not exist, and that is why it can't be closed.

where exactly are you using that code? have you added it as a plugin or how?


EDIT: you need to be more careful when reading error messages, it is not property of close like you wrote in the title, but property close of undefined, and that is something entirely different as I explained above
You should use newWin, not myWindow.
This error message basically tells you that "myWindow" is undefined, which means myWindow does not exist, and that is why it can't be closed.

where exactly are you using that code? have you added it as a plugin or how?


EDIT: you need to be more careful when reading error messages, it is not property of close like you wrote in the title, but property close of undefined, and that is something entirely different as I explained above
Oh, I see. I'm very new to JS and have to rely on tutorials that quite literally spell it out for me. I use various reasources and other people's code to figure out what I did wrong. As exactly for what the code is, the player interacts with an event and an external window pops up. The window is transparent and opened silently and after 5 second the window disappears. It's meant to give off one of those one shot effects. So, it isn't a plugin. Also, Yea, I didn't realize there was a difference. I thought they were all pretty much the same
You should use newWin, not myWindow.
Once again, I have been saved by you. It works! I'm not too good for code but I can animate and draw. I'm truly grateful and I feel so bad for asking such dummy questions.

Thank you both!

Original thread: https://forums.rpgmakerweb.com/threads/cannot-readd-property-of-close.175083/