Scripting: Saving Error

Edit- SOLVED: As usual, it was something deceptively simple.
Clearing out variable 183 in script code after closing the window fixed my issues...
Despite the fact that settings the variable to 183 in eventing did nothing.


Problem Description:
So, I'm having some saving errors on my game. The output log gives me this on save
rpg_managers.js:342 TypeError: Cannot read property 'name' of undefined
at Function.JsonEx._getConstructorName (rpg_core.js:9115)
at Function.JsonEx._encode (rpg_core.js:9035)
at Function.JsonEx._encode (rpg_core.js:9046)
at Function.JsonEx._encode (rpg_core.js:9046)
at Function.JsonEx._encode (rpg_core.js:9046)
at Function.JsonEx._encode (rpg_core.js:9046)
at Function.JsonEx.stringify (rpg_core.js:8943)
at Function.DataManager.saveGameWithoutRescue (rpg_managers.js:371)
at Function.DataManager.saveGame (rpg_managers.js:340)
at Scene_Save.onSavefileOk (rpg_scenes.js:1707)
DataManager.saveGame @ rpg_managers.js:342

But works until I try to exit the menu, at which point it brings up this error

YEP_CoreEngine.js:1094 TypeError: Cannot read property 'clamp' of undefined
at ScreenSprite.set (rpg_core.js:6170)
at Spriteset_Map.Spriteset_Base.updateScreenSprites (rpg_sprites.js:2210)
at Spriteset_Map.Spriteset_Base.update (rpg_sprites.js:2146)
at Spriteset_Map.update (rpg_sprites.js:2275)
at Spriteset_Map.Spriteset_Base.initialize (rpg_sprites.js:2131)
at Spriteset_Map.initialize (rpg_sprites.js:2261)
at new Spriteset_Map (rpg_sprites.js:2254)
at Scene_Map.createSpriteset (rpg_scenes.js:734)
at Scene_Map.createDisplayObjects (rpg_scenes.js:727)
at Scene_Map.onMapLoaded (rpg_scenes.js:571)

I've narrowed down the error to a series of scripts I have to display stuff, specifically these three sequences in a single event
◆Script:var win = new Window_Base(0,0,1024,900);
: :var string1 = $gameVariables.value(27);
: :if ($gameVariables.value(28) != -1){
: :var string2 = "PreReq: " + $gameVariables.value(122)[$gameVariables.value(28)].name;
: :} else { string2 = "No PreReq";}
: :var string3 = "Cost : " + $gameVariables.value(31);
: :var string4 = $gameVariables.value(29);
: :win.drawText(string1, 0, 50, 500, "left");
: :win.drawText(string2, 0, 200,500, "left");
: :win.drawText(string3, 0, 400,500, "left");
: :win.drawText(string4, 0, 600,600, "left");
: :$gameVariables.setValue(183, win);

◆Script:var win = $gameVariables.value(183);
: :
: :if($gameVariables.value(33) == 0){
: :string = "No Previous Grade";
: :} else {
: :string = "Last Grade: " + $gameVariables.value(33);
: :}
: :string2 = $gameVariables.value(34);
: :win.drawText(string, 500, 50, 500, "left");
: :win.drawText(string2, 700, 200, 500, "left");
: :$gameVariables.setValue(183, win);

◆Script:var win = $gameVariables.value(183);
: :win.changeTextColor("Black");
: :win.makeFontBigger();
: :win.makeFontBigger();
: :$gameVariables.setValue(183, win);
: :
: :SceneManager._scene.addChild(win);


My best guess? I'm screwing something up with loading the windows, and saving it weirdly
Clearing out variable 183 did nothing for it.(see edit)

The code structure is fairly simple, it's loading variables from an array (saved in variable 122) and then looping through to display on the screen and then allow interaction.

I'm not very experienced in javascript, so sorry if my code is terrible.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/scripting-saving-error.111947/