Changing window width doesn't show contents

I'm creating a window with the following code:
Code:
var win = new Window_Base(150, 150, 0, 72);
win.width = win.textWidthEx(LDx.variables.souls[0]) + win.standardPadding() * 10;
SceneManager._scene.addChild(win);
win.drawTextEx(String(LDx.variables.souls[0]), 0, 0);

My starting width is 0 and I changed it with 'textWidthEx', the problem is that this way even if the window is the right size the text I draw later is not showing.

What I'm doing wrong?
I don't think you changed the starting width with 'textWidthEx' - can you do the following and see the value in the console (press F8):
Code:
console.log(win.textWidthEx(LDx.variables.souls[0]));


Actually, I think 'textWidthEx' is undefined for your var win.

Try doing this to confirm my guess and let me know if it returns undefined for the second statement.
Code:
console.log(win.textWidth);
console.log(win.textWidthEx);

Var win has inherited all of the properties of Window_Base, but 'textWidthEx' is not a property of Window_Base.
Code:
console.log(win.textWidthEx);
Returns a function.

Thanks to you I found my mistake 🙂, I forgot to change the number to string (It was returning a 0):dizzy:, the code now works like this:
Code:
var win = new Window_Base(150, 150, 0, 72);
win.width = win.textWidthEx(String(LDx.variables.souls[0])) + win.standardPadding() * 10;
win.createContents();
SceneManager._scene.addChild(win);
win.drawTextEx(String(LDx.variables.souls[0]), 0, 0);
Also, I added 'win.createContents();' to refresh (win.update() didn't work).
That's interesting, in the basic rpg code 'textWidthEx' is only defined for Window_ChoiceList, so maybe you have some plugin already that adds it for Window_Base.

Good to hear it works!

Also, I added 'win.createContents();' to refresh (win.update() didn't work).

The createContents() method is already included in the intialize() method of Window_Base. The createContents() method creates the bitmap inside the window so that you can draw things on it. So when you create the new Window_Base it is already calling that method. But in your case, it is creating the contents with 0 width which is not useful to draw things on.

Try instead to switch the order, and you won't have to call createContents() anymore:
Code:
var width = win.textWidthEx(String(LDx.variables.souls[0])) + win.standardPadding() * 10;
var win = new Window_Base(150, 150, width, 72);
SceneManager._scene.addChild(win);
win.drawTextEx(String(LDx.variables.souls[0]), 0, 0);

Original thread: https://forums.rpgmakerweb.com/threads/changing-window-width-doesnt-show-contents.89668/