MV Okay, I give up. Why is this throwing a Maximum Call Stack?

Code:
(function () {
    var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
    Scene_Map.prototype.createDisplayObjects = function () {
        _Scene_Map_createDisplayObjects.apply(this, arguments);
        this._myWindow = new Window_myWindow();
        this.addChild(this._myWindow);
    };
})();

function Window_myWindow() {
    this.initialize.apply(this, arguments);
}

Window_myWindow.prototype = Object.create(Window_Base.prototype);
Window_myWindow.prototype.constructor = Window_myWindow

Window_myWindow.prototype.initialize = function (x, y, width, height) {
    Window_myWindow.prototype.initialize.call(this, 8, 8, 100, 100);
    this.refresh();
}

Window_myWindow.prototype.refresh = function () {
    this.contents.clear();
}

Window_myWindow.prototype.open = function () {
    Window_Base.prototype.open.call(this);
    this.refresh();
};

I just want to be able to display two windows, update values (gauges) and then close them when they're no longer needed. I've tried aliasing Scene_Map, I've tried a couple of other things, but the end result is always either a max call stack, or it tells me my function doesn't exist. (It does)
you don't have the create object to make the window, you
create the window using the scene.

inside that scene, you build the window you want to make,
how to open and close it.

than the window that you make, do the rest of the stuff, so you
can look how others make them, and I believe SRD and others
made some tutorials on this (mostly empty windows) how to pop it up.

so you could check those, or double check how the core make them.
Code:
Window_myWindow.prototype.initialize = function (x, y, width, height) {
    Window_myWindow.prototype.initialize.call(this, 8, 8, 100, 100);
    this.refresh();
}
initialize is calling itself
initialize is calling itself
This was the case with windows in Scene_Menu, I used this call function there and it worked fine? Why does it constantly update here?

you don't have the create object to make the window, you
create the window using the scene.

inside that scene, you build the window you want to make,
how to open and close it.
So I should be passing x, y, height, width, etc, from .create? Or .open? Is there an example of this type of window somewhere? I tried looking in Window_Message for an idea how to do this, but that also initializes itself.
create can make windows, so you can add it all there.
sizes, content, triggers, etc, otherwise, it wont be removed,
unless you do it differently.

it is also depending for what you use the window for.
create can make windows, so you can add it all there.
sizes, content, triggers, etc, otherwise, it wont be removed,
unless you do it differently.

it is also depending for what you use the window for.
I want to display the actor face and name, and a gauge for a health bar. I need two windows, and it's only for a couple of scenes so this isn't like a full game hud.

Requires window opening, closing, and updating the gauges for HP. That's it. I can work out the logic because I've already done this kind of stuff in Scene_Menu, but Scene_Map doesn't like similar instructions.

I also can't find a single tutorial that opens a custom window without first creating a custom scene, which won't work for what I need it to do. I plan to update the hud from a script call in an event.
I tried looking in Window_Message for an idea how to do this, but that also initializes itself.
that window doesn't call its own initialize in itself. it calls a parent's initialize function
Code:
Window_Message.prototype.initialize = function () {
    ...
    Window_Base.prototype.initialize.call(this, x, 0, width, height);
you are directly calling the same function in itself
Code:
Window_myWindow.prototype.initialize = function (x, y, width, height) {
    Window_myWindow.prototype.initialize.call(this, 8, 8, 100, 100);
}

This was the case with windows in Scene_Menu, I used this call function there and it worked fine? Why does it constantly update here?
are you sure you didnt call Window_Base's or some other window's that wasnt itself?
initialize is calling itself
Holy moly, this totally slipped by me. I wanted to initialize Window_Base. 🤣
are you sure you didnt call Window_Base's or some other window's that wasnt itself?
It dawned on me literally right after I posted that reply.

Silly question, but how do I actually open the window from an event, whether it was an autorun or talking to an NPC?

Code:
(function () {
    var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
    Scene_Map.prototype.createDisplayObjects = function () {
        _Scene_Map_createDisplayObjects.apply(this, arguments);
        this._myWindow = new Window_myWindow();
        this.addChild(this._myWindow);
    };
})();

This function only works when the scene changes, IE: opening menu scene
Silly question, but how do I actually open the window from an event, whether it was an autorun or talking to an NPC?
try SceneManager._scene._myWindow.show()
although, as the code is, itll be visible at the start. hide it after creation
try SceneManager._scene._myWindow.show()
although, as the code is, itll be visible at the start. hide it after creation
Okay, this works well! I don't love the idea of having the windows hiding in every single scene throughout the game though. Is there a better way I can do this, IE, addChild when I want to, and destroy the object when I no longer need it?
Okay, this works well! I don't love the idea of having the windows hiding in every single scene throughout the game though.
Its really not much to worry about, many scenes do similar, and this would only be on the map scene. Having it be persistent and then hide itself saves you from needing to keep track of whether it exists or not if you need to do anything with it. If you really wanted to, you could make a map scene function to create the window and then call that function ingame via script, but theres many roads to rome

Is there a way I can do this, IE, addChild when I want to, and destroy the object when I no longer need it?
yes, but it depends on what "when you no longer need it" is. If that's supposed to be automatic after some number of seconds, then the way I see it would involve adding onto the scene's update loop to eventually drop the window. that would come back to my earlier point of it being a bit easier having it be persistent and then only hiding when done instead of deleting it.


you reminded me of a cool thing i saw @bass2yang put together. As a part of a no plugin challenge, he created a status hud you could call via script. no plugin required. You might be interested in it, but you'd have to add a way for it to terminate. maybe flip a switch when it activates and use a parallel event to wait some number of seconds, delete the windows, and slip the switch off?
you reminded me of a cool thing i saw @bass2yang put together. As a part of a no plugin challenge, he created a status hud you could call via script. no plugin required. You might be interested in it, but you'd have to add a way for it to terminate. maybe flip a switch when it activates and use a parallel event to wait some number of seconds, delete the windows, and slip the switch off?
I'll have a look, I was in need of two separate systems. The other one went sideways enough that I opted to just control it via common events and it worked out great.

This time around, I didn't want to do that with a bunch of different drawn out gauges because I need a gauge this time. I've now manage to draw the window and art, everything looks good, but I'm struggling to figure out how to update the window via script call. Any thoughts on this?
I'm struggling to figure out how to update the window via script call. Any thoughts on this?
it depends on how often its supposed to update. If its infrequent enough that you can have events that call the window in the first place, then you can use those same events to refresh the window or redraw the gauges. if it needs to be constantly be updating at al times unprompted, then you'd add it to the scene's update loop to refresh when visible.
it depends on how often its supposed to update. If its infrequent enough that you can have events that call the window in the first place, then you can use those same events to refresh the window or redraw the gauges. if it needs to be constantly be updating at al times unprompted, then you'd add it to the scene's update loop to refresh when visible.
Yeah, refresh is the way to go for sure. I've already setup the function but when I try to update it's commands, like lets say:
Window_MyWindow.prototype.refresh(value1, value2);

It returns:
Uncaught TypeError: Cannot read property 'bitmap' of undefined
Yeah, refresh is the way to go for sure. I've already setup the function but when I try to update it's commands, like lets say:
Window_MyWindow.prototype.refresh(value1, value2);

It returns:
Uncaught TypeError: Cannot read property 'bitmap' of undefined
for future reference, share the trace and not just the final line.
if calling refresh is resulting in error, then the bitmap inside the contents property of your window was removed. AFAIK, you wouldnt be able to get that unless you unintentionally called a function to do so, or it never had a bitmap to begin with
for future reference, share the trace and not just the final line.
if calling refresh is resulting in error, then the bitmap inside the contents property of your window was removed. AFAIK, you wouldnt be able to get that unless you unintentionally called a function to do so, or it never had a bitmap to begin with
I didn't think the trace would be relevant, there's nothing exciting there. It just tells me the line it failed on, which was line 39. Line 39 is the first line of Window_MyWindow.prototype.refresh.

I don't understand what you mean by the bitmap inside the contents property, but basically the window draws the 2 text boxes, a gauge, and an actor face:
Code:
Window_MyWindow.prototype.create = function (faceImg, faceValue, name, gaugeValue) {
    var x = 8;
    var y = 8;
    var width = 400;
    var height = 178;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.drawFace(faceImg, faceValue, 0, 0, 144, 144);
    this.drawTextEx('\\C[3]' + name, 144 + 18, 0, this.width - this.padding * 2, "left");
    this.drawGauge(144 + 16, 20, 200, gaugeValue, this.hpGaugeColor1(), this.hpGaugeColor2());
    this.drawTextEx('Attack', 144 + 18, 52, this.width - this.padding * 2, "left");
    // this.hide();
}

I've simplified refresh for now as:
Code:
Window_MyWindow.prototype.refresh = function () {
    this.contents.clear();
}

This will throw the error. I also tried:
Code:
Window_MyWindow.prototype.refresh = function (faceImg, faceValue, name, gaugeValue) {
    this.drawFace(faceImg, faceValue, 0, 0, 144, 144);
    this.drawTextEx('\\C[3]' + name, 144 + 18, 0, this.width - this.padding * 2, "left");
    this.drawGauge(144 + 16, 20, 200, gaugeValue, this.hpGaugeColor1(), this.hpGaugeColor2());
    this.drawTextEx('Attack', 144 + 18, 52, this.width - this.padding * 2, "left");
}

I'm obviously misunderstanding, but when it returns this undefined bitmap property, there is an actor face drawn there. It does show up, but I can't replace it. I can't really do anything because outside of throwing a console.log("Test"); in there, which will pass, it fails any other input including clear.
I don't understand what you mean by the bitmap inside the contents property, but basically the window draws the 2 text boxes, a gauge, and an actor face:
i misspoke a bit trying to get it out quickly.

I didn't think the trace would be relevant, there's nothing exciting there. It just tells me the line it failed on, which was line 39. Line 39 is the first line of Window_MyWindow.prototype.refresh.
Your error is that the game cant access something thats supposed to have a bitmap property (that thing is undefined and thus, was never set up or was removed), but your refresh itself doesnt directly do that. If the error is ultimately from refresh, then its likely something called within contents.clear(). The trace would have been more information about whats happening there
i misspoke a bit trying to get it out quickly.


Your error is that the game cant access something thats supposed to have a bitmap property (that thing is undefined and thus, was never set up or was removed), but your refresh itself doesnt directly do that. If the error is ultimately from refresh, then its likely something called within contents.clear(). The trace would have been more information about whats happening there
Code:
Uncaught TypeError: Cannot read property 'bitmap' of undefined
    at Window_Base.get (rpg_core.js:6358)
    at Window_Base.Window_MyWindow.refresh (Khali_MyScript.js:44)
    at <anonymous>:1:27
get    @    rpg_core.js:6358
Window_MyWindow.refresh    @    Khali_MyScript.js:44
(anonymous)    @    VM1018:1

VM1018:1 just returns my refresh function.

Someone has to have run into this problem before, it doesn't cause this in any other scene. It has nothing to do with contents.clear() in the function, because if I remove it, the function will work. I can even send console logs. If I do anything in regard to bitmaps (drawText, drawFace, contents.clear()) it fails and I can not understand why. I can also only draw on create, I tried passing to refresh and calling from create and it throws the same error.

I don't need to know that there's an undefined value, I need to know why. Can you write a basic gauge script with a refresh function that successfully works so I have something to compare to?

After a large amount of google searching, apparently, no one else has run into this, but there are tons of scripts with gauges.

Like, what am I missing? Is there a function to erase specific bitmaps or something that I'm not aware of?

By name, I would just assume that this.contents.clear() would gather everything in the window and delete it. It appears to do that when it's not being used on Scene_Map.
It has nothing to do with contents.clear() in the function, because if I remove it, the function will work
normally that means theres a relation of some kind. if it works without it and fails with it, theres some piece related to it that should be examined.

at Window_Base.get (rpg_core.js:6358)
this is why its always good to show the trace. contents is a function call in and of itself for _windowContentsSprite.bitmap. which means if _windowContentsSprite is undefined, its exactly the error you'd get for doing anything with contents. However, Windows at the lowest level initialize with that being null. so its a safe assumption that its being deleted by something after you create them.

If I do anything in regard to bitmaps (drawText, drawFace, contents.clear()) it fails and I can not understand why. I can also only draw on create, I tried passing to refresh and calling from create and it throws the same error.
you would have to show the entire plugin to share all your changes. because if youre using a "create" function to create the window, youre already working with something custom and theres too much unknown to say anything for certain.
For example, I dont know where that function is being called without seeing it. Scenes have a create function thats used to create all of their needed windows and is called automatically when they start. I cant make the same assumption for a window. Thats normally the role of initialize for them

Like, what am I missing? Is there a function to erase specific bitmaps or something that I'm not aware of?
No idea. what you had in the first post works just fine when you correct initialize's recursion, add in your refresh you last shared, and hook it up to the scene's update. All i did past that was set up the window to specifically show the party leader data for testing's sake

tes.gif

Spoiler
Code:
(function () {
    var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
    Scene_Map.prototype.createDisplayObjects = function () {
        _Scene_Map_createDisplayObjects.apply(this, arguments);
        this._myWindow = new Window_myWindow();
        this.addChild(this._myWindow);
        //this._myWindow.hide()
    };

    function Window_myWindow() {
        this.initialize.apply(this, arguments);
    }

    Window_myWindow.prototype = Object.create(Window_Base.prototype);
    Window_myWindow.prototype.constructor = Window_myWindow

    Window_myWindow.prototype.initialize = function (x, y, width, height) {
        Window_Base.prototype.initialize.call(this, 8, 8, 400, 178);
        this.refresh();
    }

    Window_myWindow.prototype.refresh = function (faceImg, faceValue, name, gaugeValue) {
        actor = $gameParty.members()[0]
        faceImg = actor.faceName()
        faceValue = 0;
        name = actor.name()
        gaugeValue = actor.hpRate()
        this.drawFace(faceImg, faceValue, 0, 0, 144, 144);
        this.drawTextEx('\\C[3]' + name, 144 + 18, 0, this.width - this.padding * 2, "left");
        this.drawGauge(144 + 16, 20, 200, gaugeValue, this.hpGaugeColor1(), this.hpGaugeColor2());
        this.drawTextEx('Attack', 144 + 18, 52, this.width - this.padding * 2, "left");
    }


    Window_myWindow.prototype.open = function () {
        Window_Base.prototype.open.call(this);
        this.refresh();
    };

    var alias = Scene_Map.prototype.update
    Scene_Map.prototype.update = function () {
    alias.call(this);
    this._myWindow.refresh()
};

})();
That post was hugely helpful. I made modifications to my script to match what you had going on here, but I don't fully understand why it was causing issues the way I had it.

I was calling everything from create() instead of refresh() because refresh kept coming back that the bitmap was undefined. The differences I noticed from my original plugin to yours is that I never used an alias for Scene_Map.prototype.update().

When I was getting the error I was simply calling Window_MyWindow.prototype.refresh(), could this be the cause for the errors and why clear had failed?

Either way, I managed to complete the script and setup separate functions I can use from script calls to update the actor faces, names, actions, and gauges for both actors. (There's 2 gauges now)

I'm hugely greatful for your help!

Original thread: https://forums.rpgmakerweb.com/threads/okay-i-give-up-why-is-this-throwing-a-maximum-call-stack.179062/