How to draw Icons straight from your Icon Sheet?

I've created an additional window in a custom menu and I'm able to display values from variables.
However, I can't figure out how to display them along with icons without any error.
The function below gives me the icon appearing behind "undefined" text, so it visually appears as:

"[icon]defined Player Score: "
*un appearing above the icon

Code:
    Window_New.prototype.iconPlayerScore = function() {

        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = 32;  //Window_Base._iconWidth;
        var ph = 32;  //Window_Base._iconHeight;
        var sx = 87 % 16 * pw;
        var sy = Math.floor(87 / 16) * ph;
        return this.contents.blt(bitmap, sx, sy, pw, ph, 1, 1); //x, y

    };

What am I doing wrong? I also don't understand how to interpret the x and y values for the blt function. I just placed 1 for now.
There's a function called "drawIcon" it's meant for this kinda thing in Window_Base (rpg_windows line 430) are you drawing this outside a window?
You can ask my pal directly, he is really good on this stuff!
https://forums.rpgmakerweb.com/index.php?members/dsiver144.20540/
There's a function called "drawIcon" it's meant for this kinda thing in Window_Base (rpg_windows line 430) are you drawing this outside a window?

Code:
Window_Base.prototype.drawIcon = function(iconIndex, x, y) {
    var bitmap = ImageManager.loadSystem('IconSet');
    var pw = Window_Base._iconWidth;
    var ph = Window_Base._iconHeight;
    var sx = iconIndex % 16 * pw;
    var sy = Math.floor(iconIndex / 16) * ph;
    this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
};

Yea, it's practically the same as the function I made. I just hard coded the values for iconIndex, x and y. The latter two of which I don't understand.
The contents of the function are the same and should work despite the function's name right? (My custom function inherited from window_base as well)

What is x and y? Could that be the reason for my problem?
x and y are the coordinates relative to the window where the block transfer will be applied. I think (1, 1) should be okay, so I'm not sure why it's not appearing. Your new window class is called Window_New, right?
x and y are the coordinates relative to the window where the block transfer will be applied. I think (1, 1) should be okay, so I'm not sure why it's not appearing. Your new window class is called Window_New, right?

(I tend to change the names when I post here, lol) Code is:

Code:
    function Window_ZenInfo() {
        this.initialize.apply(this, arguments);
    }

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

    Window_ZenInfo.prototype.initialize = function(x, y) {
        var width = this.windowWidth();
        var height = this.windowHeight();
        Window_Base.prototype.initialize.call(this, x, y, width, height);
        this.refresh();
    };

    Window_ZenInfo.prototype.windowWidth = function() {
        return (Graphics.boxWidth / 2);
    };

    Window_ZenInfo.prototype.windowHeight = function() {
        return this.fittingHeight(2);
    };

    Window_ZenInfo.prototype.refresh = function() {
        var x = this.textPadding();
        //var x2 = 0;
        var width = this.contents.width - this.textPadding() * 2;
        this.contents.clear();
       
        this.drawText(this.iconPlayerScore() + "Score: " + this.valuePlayerScore(), x, 0, width, 'left');
        this.drawText("Movements: " + this.valuePlayerMovements(), x, 0, width, 'right');
        this.drawText("Zen: " + this.valueMoney(), x, this.lineHeight() * 1, width, 'left');
        this.drawText("Playtime: " + this.valuePlaytime(), x, this.lineHeight() * 1, width, 'right');

    };

Code:
    Window_ZenInfo.prototype.iconPlayerScore = function() {

        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = 32;//Window_Base._iconWidth;
        var ph = 32;//Window_Base._iconHeight;
        var sx = 87 % 16 * pw;
        var sy = Math.floor(87 / 16) * ph;
        return this.contents.blt(bitmap, sx, sy, pw, ph, 5, 5);

        //2;
        //return TextManager.currencyUnit;
        //return this.drawIcon($dataItems[399].iconIndex, 0, 0); //this.drawIcon(icons[87], 5, 5);
        //this.drawIcon(icons[87], x + Window_Base._iconWidth * i, y + 2);
    };

Using drawText for now because that's how I saw two other scripts do it (though it's confusing to me).
And oh good. It's relative to the drawn window and not the screen (I was hoping for that).

Edit: This is a picture of the problem:
Is there a particular reason that you're drawing the text for score/movements and zen/playtime at the same x and y coordinates? That will definitely cause some overlap. 😛

Oh, I see what's causing that undefined. Remove the "return" at the beginning of your block transfer line.
Is there a particular reason that you're drawing the text for score/movements and zen/playtime at the same x and y coordinates? That will definitely cause some overlap. 😛

Oh, I see what's causing that undefined. Remove the "return" at the beginning of your block transfer line.

I had x2 for that reason, but also thought the left/right alignments took care of that since visually they appear correctly aligned. (I edited in an image later)

Also, I suspected that about returm and tried that before to no success. Just removed the return again and same undefined error.
Also removed the other three instances of drawText, but same problem.
Can you paste what your code looks like now just so I have a fresh version to work from?

Edit: Christ, why did I miss this? I wasn't looking closely enough.

Okay, so the thing about drawText is that it draws text. It doesn't draw icons. You need to call your icon drawing function separately. It can't be concatenated into a string, because it's a picture. Although your code will draw an icon with a string next to it, there is literally no connection between the two as far as Javascript is concerned, so trying to call a function inside a function that just displays text is going to return "undefined".

To put it in a more understandable way, what's currently happening is that drawText is trying to output the return value of your icon drawing function as text, which gets "undefined" because the block transfer function doesn't return a value.
Can you paste what your code looks like now just so I have a fresh version to work from?

Edit: Christ, why did I miss this? I wasn't looking closely enough.

Okay, so the thing about drawText is that it draws text. It doesn't draw icons. You need to call your icon drawing function separately. It can't be concatenated into a string, because it's a picture. Although your code will draw an icon with a string next to it, there is literally no connection between the two as far as Javascript is concerned, so trying to call a function inside a function that just displays text is going to return "undefined".

To put it in a more understandable way, what's currently happening is that drawText is trying to output the return value of your icon drawing function as text, which gets "undefined" because the block transfer function doesn't return a value.

Ohhhh. I understand what you're saying about text and non-text. The blt function itself draws the icon, but the drawText function tries to interpret that function call as text.

Edit: Can I ask another question related to what I'm doing? About refreshing.
Sure, it's your topic, ask whatever you want. 😛
Sure, it's your topic, ask whatever you want. 😛

Well, I wasn't sure if it would be considered off-topic and require me to start a new post.

Code:
    Window_ZenInfo.prototype.valuePlaytime = function() {
        return $gameSystem.playtimeText();
    };

gives the playtime for me, but it doesn't update within the menu. I have to close and re-enter to see the time updated.
I was looking at how others drew the playtime. One being:

Code:
    Window_SumRndmMenuInfo.prototype.refresh = function() {
        var x = this.textPadding();
        var width = this.contents.width - this.textPadding() * 2;
        this.contents.clear();
        var items = Math.min(4, sumItemOrder.length)
        for(var i = 0; i < items; i++) {
            var item = sumItemOrder[i];
            if(item.match(/(?:playtime|time|play)/i)) {
                this.drawText(playtimeText + " " + $gameSystem.playtimeText(), x, this.lineHeight() * i, width, 'left');
            } else if(item.match(/location/i)) {
                var mapName = (sumDisplayName) ? $gameMap.displayName() : $dataMapInfos[$gameMap.mapId()].name;
                this.drawText(locationText + " " + mapName, x, this.lineHeight() * i, width, 'left');
            } else if(item.match(/(?:bgm|music)/i)) {
                this.drawText(bgmText + " " + AudioManager.sumRndmCurrentBgm(), x, this.lineHeight() * i, width, 'left');
            } else if(item.match(/battle/i)) {
                this.drawText(battlesText + " " + $gameSystem.battleCount(), x, this.lineHeight() * i, width, 'left');
            }
        }
    };

I can't identify what causes it to update in real time, which is what I'd like.

Edit: Forgot to include my refresh function

Code:
    Window_ZenInfo.prototype.refresh = function() {
        var x = this.textPadding();
        var x2 = 0;
        var width = this.contents.width - this.textPadding() * 2;
        this.contents.clear();
             
        this.drawText(this.iconPlayerScore() + "Score: " + this.valuePlayerScore(), x, 0, width, 'left');
        this.drawText("Movements: " + this.valuePlayerMovements(), x, 0, width, 'right');
        this.drawText("Zen: " + this.valueMoney(), x, this.lineHeight() * 1, width, 'left');
        this.drawText("Playtime: " + this.valuePlaytime(), x, this.lineHeight() * 1, width, 'right');

  
    };
Refresh is usually used to update the window in response to a change in input, such as when you press page up/page down to move through actors in the skill window. If you want it to continuously update regardless of what the player is doing, put it in the update function instead.
Refresh is usually used to update the window in response to a change in input, such as when you press page up/page down to move through actors in the skill window. If you want it to continuously update regardless of what the player is doing, put it in the update function instead.



You give me a hint and additional knowledge when it comes on "refresh function" it cause ma a day to solve my issue thanks 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-to-draw-icons-straight-from-your-icon-sheet.75157/