Get variables/actor name within manual text display?

Hey all,

Due to the type of project I am working on, the built-in text display function won't be either aesthetically or mechanically pleasing. It's taken some time, but eventually I did find the code to create text within a new window manually via script call:

Code:
var window = new Window_Base(x, y, width, height);
window.drawText("Hello World", x, y, maxWidth, lineHeight, alignment);
SceneManager._scene.addWindow(window);

This works swimmingly, and I probably would have gotten it to work sooner if I'd actually known what I was doing. But, as I am currently uneducated in the ways of JavaScript, I've been unable to figure out how to draw the name of X actor within the text, or draw any variables at all. Of course, codes used in the built-in message windows (such as \N[X] or \V[X]) will not work here, as they are not defined. But I am unsure of what my plan is here, I don't know how to define these commands to get the response I'm looking for.

If anyone can help me out, that would be awesome. I'm happy to provide more details if necessary, I realize I'm definitely missing something obvious.
PHP:
// Get the name of the actor with id 4
var actorName = $gameActors.actor(4).name();

PHP:
// Get the value of variable with id 42
var value = $gameVariables.value(42);

PHP:
// Draw the value of variable 42
var value = $gameVariables.value(42);
window.drawText(value, x, y, maxWidth);
@waynee95 Thanks, this definitely helps! I have one last question, however: For the actor's name in particular, after defining it, is there any way to make it appear within the "Hello World" of the drawText, or must that be done separately? (I'm sorry if that's a silly question, I'd just like to make sure I'm doing all this correctly.)
Yes you can do that.

PHP:
// You can add any variables to the the text. Just make sure to have the text always between "" and variables are added with a +
// Note: actorName refers to the code above, I was too lazy to type it again xD
window.drawText("Hello World" + actorName + "Hello World.", x, y, maxWidth);
@waynee95 Awesome! Thanks again! 😀
now question... how to close that window once it's created?
I waited to bump this, does anyone know how to get a window to close once it's created in this way?
window.close()

It's a method in the Window_Base class.

Original thread: https://forums.rpgmakerweb.com/threads/get-variables-actor-name-within-manual-text-display.82460/