MV Cant seem to get this plugin to work.

So, the plugin is something ive been trying to make and cant seem to get what i want it to do. I want help configuring it and have the same affect in the harvest moon or rune factory games with romance options, theres 6 hearts, each heart is 1000 points of affection, the max affection is 6000 so 6 hearts in total, with five stages of each heart,

empty
1/4
1/2
3/4
and full

any help with this plugin could help,

JavaScript:
/*:
 * @plugindesc Displays a heart meter based on affection points in events with a <HeartMeter: varID> note tag.
 * @author Ponimeimei & SilverWire
 *
 * @help
 * Add the following note tag to the main event notetag to display a heart meter:
 *
 * <HeartMeter: affectionVar>
 *
 * - affectionVar: ID of the variable where affection points are stored.
 */

(function() {
    const maxHearts = 6; // Maximum number of hearts
    const heartImages = {
        0: 'EmptyHeart',
 1: '1-4Heart',
 2: 'HalfHeart',
 3: '3-4Heart',
 4: 'FullHeart'
    };

    const heartSprites = {}; // Store heart sprites by event ID

    // Load heart images into memory
    function preloadHeartImages() {
        Object.values(heartImages).forEach(image => {
            ImageManager.loadPicture(image);
        });
    }

    // Retrieve the affection variable ID from event's notetags
    function getAffectionVarId(event) {
        const note = event.event().note;
        const regex = /<HeartMeter:\s*(\d+)>/i;
        const match = note.match(regex);
        return match ? Number(match[1]) : null;
    }

    // Initialize heart sprites for an event
    function initializeHeartSprites(eventId) {
        heartSprites[eventId] = [];
        for (let i = 0; i < maxHearts; i++) {
            const sprite = new Sprite();
            sprite.bitmap = ImageManager.loadPicture(heartImages[0]); // Set to EmptyHeart
            sprite.visible = false; // Hide initially
            SceneManager._scene.addChild(sprite);
            heartSprites[eventId].push(sprite);
        }
    }

    // Determine heart state based on affection points
    function determineHeartState(affectionPoints, maxAffection) {
        const affectionPerHeart = maxAffection / maxHearts;
        const fullHearts = Math.floor(affectionPoints / affectionPerHeart);
        const remainder = affectionPoints % affectionPerHeart;

        // Calculate the heart state
        const heartStates = Array(maxHearts).fill(0);
        for (let i = 0; i < fullHearts && i < maxHearts; i++) {
            heartStates[i] = 4; // Full heart
        }

        // Check remainder for partial hearts
        if (fullHearts < maxHearts) {
            if (remainder > affectionPerHeart * 0.75) {
                heartStates[fullHearts] = 3; // 3/4 heart
            } else if (remainder > affectionPerHeart * 0.5) {
                heartStates[fullHearts] = 2; // 1/2 heart
            } else if (remainder > affectionPerHeart * 0.25) {
                heartStates[fullHearts] = 1; // 1/4 heart
            }
        }

        return heartStates;
    }

    // Update heart sprites based on affection points
    function updateHeartSprites(event) {
        const eventId = event.eventId();
        const affectionVarId = getAffectionVarId(event);

        // Logging for debugging
        console.log(`Event ID: ${eventId}, Affection Var ID: ${affectionVarId}`);

        if (affectionVarId === null || !event.page()) {
            hideHeartSprites(eventId);
            return;
        }

        const affectionPoints = $gameVariables.value(affectionVarId);
        const maxAffection = 6000; // Define the maximum affection points
        const heartStates = determineHeartState(affectionPoints, maxAffection);

        // Show and update heart sprites
        if (!heartSprites[eventId]) initializeHeartSprites(eventId);
        heartSprites[eventId].forEach((sprite, index) => {
            sprite.bitmap = ImageManager.loadPicture(heartImages[heartStates[index]]);
            sprite.visible = true; // Make heart visible
            sprite.x = event.screenX() + (index * 32); // Position hearts
            sprite.y = event.screenY() - 48; // Above the event

            // Logging for each heart update
            console.log(`Heart ${index + 1}: ${heartStates[index]}, Affection Points: ${affectionPoints}`);
        });
    }

    // Hide all heart sprites for an event
    function hideHeartSprites(eventId) {
        if (heartSprites[eventId]) {
            heartSprites[eventId].forEach(sprite => {
                sprite.visible = false;
            });
        }
    }

    // Update heart meters every frame
    function updateHeartMeters() {
        $gameMap.events().forEach(event => {
            if (isPlayerCloseToEvent(event)) {
                updateHeartSprites(event);
            } else {
                hideHeartSprites(event.eventId());
            }
        });
    }

    // Check if the player is within range of the event
    function isPlayerCloseToEvent(event) {
        const playerX = $gamePlayer.x;
        const playerY = $gamePlayer.y;
        const eventX = event.x;
        const eventY = event.y;
        return Math.abs(playerX - eventX) <= 2 && Math.abs(playerY - eventY) <= 2;
    }

    // Hook into Scene_Map's update method
    const _Scene_Map_update = Scene_Map.prototype.update;
    Scene_Map.prototype.update = function() {
        _Scene_Map_update.call(this);
        updateHeartMeters();
    };

    // Preload heart images when the game starts
    const _Scene_Boot_start = Scene_Boot.prototype.start;
    Scene_Boot.prototype.start = function() {
        _Scene_Boot_start.call(this);
        preloadHeartImages();
    };

})();
So, the plugin is something ive been trying to make and cant seem to get what i want it to do.
You need to provide more specific details than this.

I think it's a little unreasonable to expect other people to read through your entire plugin's code and try to find some error someplace (or take the time to install and set it up and test it to see what's wrong).

What is the actual problem? What happens instead of what you want?
You need to provide more specific details than this.

I think it's a little unreasonable to expect other people to read through your entire plugin's code and try to find some error someplace (or take the time to install and set it up and test it to see what's wrong).

What is the actual problem? What happens instead of what you want?
you know instead of being snarky you could have simple just said the last sentence.

but anyway.

I try to test the plugin, and it seems that when i get in range of a marriage candidate, the hearts do not update when the event gives the affection points (when i talk to them) and the whole meter disappears.
you know instead of being snarky you could have simple just said the last sentence.
"When others do a foolish thing, you should tell them it is a foolish thing. They can still continue to do it, but at least the truth is where it needs to be." - Dukhat, Babylon 5

Seriously tho, it's not snarky letting you know that you're likely not getting any help asking for something unreasonable. We gotta normalize not being offended at everything again.
you know instead of being snarky you could have simple just said the last sentence.
I'm not being snarky - it's basic practice for getting help that you need to describe the problem, and it's even in the section guidelines. Leaving it out is either a major thing to forget, or presenting the thread with the expectation that other people will go to significant effort to help you.

But anyway.

I try to test the plugin, and it seems that when i get in range of a marriage candidate, the hearts do not update when the event gives the affection points (when i talk to them) and the whole meter disappears.
What have you tried for troubleshooting? Have you put console.log() calls inside the conditional branches of updateHeartMeters() to verify which branch is being executed? Because that seems to be the problem, right, that the event is getting hideHeartSprites() called on it?

What do the console logs in updateHeartSprites() say? (again, provide us with information on the problem)

A few side notes, unrelated to your issue:

Personally, instead of iterating through every event on the map every frame (which could potentially be a large list) just to see if the player is in/out of range, I would simply check all map coordinates within a radius of the player, then update based on any events on those tiles. Depending on the map, it could be significantly more efficient.

Have you considered, instead of so many global functions, making all of this methods of the Scene_Map?

Original thread: https://forums.rpgmakerweb.com/threads/cant-seem-to-get-this-plugin-to-work.172598/