MV $gameVariables.setValue(var, value) not seeming to work.

Hello there, fellow game-makers!
I am using the below script as a common event to try and create a unique variable that stores usage information of a skill. Once the skill hits the threshold (3 for the test), it is supposed to upgrade the skill for the next skill.id+1 skill. For some reason, the uniqueId variable keeps resetting at the end and I'm really hoping I'm just missing something simple.
Spoiler: Common Event script
JavaScript:
const actorId = $gameVariables.value(1);
const skillId = $gameVariables.value(2);
const user = $gameActors.actor(actorId);
let uniqueId = actorId * 1000 + skillId; console.log("uniqueId: " + uniqueId);

if($gameVariables.value(uniqueId) === 0){
    $gameVariables.setValue(uniqueId, 0); console.log("Initializing uniqueId " + uniqueId + " to 0");
}
else{console.log("Variable " + uniqueId + " already initialized with value: " + $gameVariables.value(uniqueId));}

let usageCount = $gameVariables.value(uniqueId);
usageCount += 1;
$gameVariables.setValue(uniqueId, usageCount); console.log("Incremented uniqueId value: " + $gameVariables.value(uniqueId) + "; and usageCount: " + usageCount);
const threshold = 3;
if ($gameVariables.value(uniqueId) >= threshold) {console.log("Threshold reached! Upgrading skill...");
    user.learnSkill(skillId + 1); console.log("Learned skill " + (skillId + 1));
    user.forgetSkill(skillId); console.log("Forgot skill " + skillId); $gameVariables.setValue(uniqueId, 0);}
else {console.log("Usage count hasn't reached the threshold yet.");}
console.log("Final uniqueId count value: " + $gameVariables.value(uniqueId) + " and uniqueId: " + uniqueId);
Spoiler: Skill notetag field
<Custom Execution>
$gameTemp.reserveCommonEvent(15);
$gameVariables.setValue(1, user._actorId);
$gameVariables.setValue(2, skill.id);
</Custom Execution>
Spoiler: Log from game showing failure:
1740891354624.png

Thanks, in advance, for anyone willing to help!
Maybe the reserveCommonEvent should be under the $gameVariables.setValue in the skill notetag?
did you increase your maximum variables to be able to include the ids of the ones youre trying to set? if you try to set the value of a variable that is past what you set as your game's maximum, the engine doesnt try do anything to it.
@TESTOSTERONE
while it is a better programming style to set the variables before reserving the common event, that doesn't matter here because the common event is only processed later - as can be seen by the fact that the unique ID was calculated.

No, I think the problem is here:

if($gameVariables.value(uniqueId) === 0){ $gameVariables.setValue(uniqueId, 0); console.log("Initializing uniqueId " + uniqueId + " to 0");

the condition always registers as true, which always resets the value.
comparisons are usually done wit ==, not ===
please try that

If that doesn't solve the problem, please post a screenshot of the full common event instead of only the script text. That means including trigger etc.
the condition always registers as true, which always resets the value.
comparisons are usually done wit ==, not ===
both are equals comparisons, but the triple is needed when youre making strict comparisons to 0. with the double equals sign, any falsy value makes the condition true and then you get stuff like ""==0, false==0, and []==0 being accepted.
JavaScript:
if($gameVariables.value(uniqueId) === 0){
    $gameVariables.setValue(uniqueId, 0); console.log("Initializing uniqueId " + uniqueId + " to 0");
}
else{console.log("Variable " + uniqueId + " already initialized with value: " + $gameVariables.value(uniqueId));}

let usageCount = $gameVariables.value(uniqueId);
usageCount += 1;

I don't get this really, as unique id = actor ID + 1 in usageCount, as this could be 0 everytime.
shouldn't usage count have a different ID? or use a small array for [uniqueId, threshhold]?

I can be wrong, but also: user.learnSKill and user.forgetSkill() aren't correct probably either outside
the notetag of those skills that you use on them?
did you increase your maximum variables to be able to include the ids of the ones youre trying to set? if you try to set the value of a variable that is past what you set as your game's maximum, the engine doesnt try do anything to it.
This is something I have yet to do, but I am within the initial 5000 variable maximum. I'll definitely have to either change the variable range for my uniqueId variable, increase the maximum variable count, or set these into an array - but I'll do that at a later time. Thank you for the reminder, though!

the condition always registers as true, which always resets the value.
comparisons are usually done wit ==, not ===
please try that

If that doesn't solve the problem, please post a screenshot of the full common event instead of only the script text. That means including trigger etc.
Tested it, and that did not help - I was admittedly hoping that would do it. xD
Spoiler: Log values
1740931794491.png
Spoiler: Common event screenshot
1740933127160.png
This is something I have yet to do, but I am within the initial 5000 variable maximum.
The initial maximum is 10? 20?

The editor's absolute maximum is 5000, but i wasnt talking about that. Theres a maximum variable quantity that you set within the editor's variable window. until you change the maximum value there, the game isnt going to use any variable past it.

1740934807639.png
The initial maximum is 10? 20?

The editor's absolute maximum is 5000, but i wasnt talking about that. Theres a maximum variable quantity that you set within the editor's variable window. until you change the maximum value there, the game isnt going to use any variable past it.

View attachment 333100
Oh, yeah. I did this forever ago. lol. Thank you, though!
then we have to experiment to see what else we can find.

1) in the common event, before the script command, please add a line control variable (1052) = 1
This is just to see how it changes the output and help pinpointing where everything went wrong.

2) in the common event, in the script, please copy the line that begins with "let usageCount" and directly post it here.
In the first post you reformatted it for better readability, and I want to check if you hadn't corrected a typo with that step. Especially as the later parts of that line are not visible unless you go in and scroll, a mistake there might be overlooked.
then we have to experiment to see what else we can find.

1) in the common event, before the script command, please add a line control variable (1052) = 1
This is just to see how it changes the output and help pinpointing where everything went wrong.

2) in the common event, in the script, please copy the line that begins with "let usageCount" and directly post it here.
In the first post you reformatted it for better readability, and I want to check if you hadn't corrected a typo with that step. Especially as the later parts of that line are not visible unless you go in and scroll, a mistake there might be overlooked.
Huh... I completely shutdown my laptop last night and now everything works. Maybe it was holding some incorrect cookies? Thank you all for your help!
1741016985027.png

UseCount went up properly, then the skills were forgotten and replaced appropriately at that point.

Original thread: https://forums.rpgmakerweb.com/threads/gamevariables-setvalue-var-value-not-seeming-to-work.175932/