Is it possible to set a variable through the map notes?

The title is self-explainatory. Is it possible to change the value of a variable using a command in the map notes, that runs when you enter a map? Maybe using a plugin?
Yes, it's possible, but it would be more practical to simply create a map event in a parallel process that is deleted when triggered.

But if you find the effect too slow for events that depend on this event, this plugin might solve the problem. I wrote this without testing it because I'm not at home.
JavaScript:
(function () {
    const _GP_transfer = Game_Player.prototype.performTransfer;
    Game_Player.prototype.performTransfer = function() {
        if (this.isTransferring()) {
            if ($dataMap.meta.setVariable) {
                const setvar = $dataMap.meta.setVariable.split(",");
                $gameVariables.setValue(Number(setvar[0])|0,Number(setvar[1])|0); /* By Caethyril*/
            }
        }
        _GP_transfer.call(this);
    }
})();

In the map notes:
<setVariable: ID Variable, Value>

Example (variable 15, set value 500):
<setVariable:15,500>
Yes, it's possible, but it would be more practical to simply create a map event in a parallel process that is deleted when triggered.

But if you find the effect too slow for events that depend on this event, this plugin might solve the problem. I wrote this without testing it because I'm not at home.
JavaScript:
(function () {
    const _GP_transfer = Game_Player.prototype.performTransfer;
    Game_Player.prototype.performTransfer = function() {
        if (this.isTransferring()) {
            if ($dataMap.meta.setVariable) {
                const setvar = $dataMap.meta.setVariable.split(",");
                $gameVariables.setValue(setvar[0], setvar[1]);
            }
        }
    }
    _GP_transfer.call(this);
})();

In the map notes:
<setVariable: ID Variable, Value>

Example (variable 15, set value 500):
<setVariable:15,500>
Thank you so much for your time.

I tried running the plugin and it gives me this error when I run the game
It seems to be a conflict with some plugin; this addRect function is related to graphs. When I get home I'll test it and confirm if I wrote anything wrong.
I see the error: the _GP_transfer.call(this) line is misplaced. It should be moved up one line.
I just tested it, and the error is different:
TypeError
this.isTransferring is not a function

From what I saw, I ended up placing the function outside of the prototype. Now it's fixed. The function error may have broken another plugin not mentioned by the OP.
I would also recommend converting the split values from string to number, e.g.
JavaScript:
                $gameVariables.setValue(setvar[0] | 0, setvar[1] | 0);
I would also recommend converting the split values from string to number, e.g.
JavaScript:
                $gameVariables.setValue(setvar[0] | 0, setvar[1] | 0);
would that not only work with lower numbers as big numbers can end up negatives?

wouldn't it be saver to use || 0 if it can be string?
wouldn't it be saver to use|| 0 if it can be string?
that logical OR wouldnt produce a number unless the string was empty. if the bitwise OR ends up presenting a problem, casting it into a number with Number() should still work regardless
I don't remember the most practical way to convert a String to a number.
(Number(setvar[0]))?Number(setvar[0]):0,(Number(setvar[1]))?Number(setvar[1]):0;
Or:

setvar[0]=Number(setvar[0])|0; setvar[1]=Number(setvar[1])|0;

Please disregard... my lack of attention.
No worries!
Spoiler: some convert-to-integer options & their drawbacks
  • Number(v) or +v returns a number, NaN if non-numeric.
    • May return a non-integer value.
  • parseInt(v, 10) returns an integer (truncated), or NaN if non-numeric.
    • Does not recognise notations like 0b10 or 1e6.
  • v | 0 returns a 32-bit integer (truncated), 0 if non-numeric.
    • Only correct for values in the range -2³¹ ≤ v ≤ 2³¹ - 1.
  • isNaN(v) ? 0 : Math.trunc(Number(v)) returns an integer (truncated), 0 if non-numeric.
    • Clunky but doesn't have the range limit of v | 0 (if that's a concern).

@ShadowDragon - like Robro implied, || is logical OR, | is bitwise OR.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-set-a-variable-through-the-map-notes.182392/