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.
Thanks, in advance, for anyone willing to help!
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.
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);
<Custom Execution>
$gameTemp.reserveCommonEvent(15);
$gameVariables.setValue(1, user._actorId);
$gameVariables.setValue(2, skill.id);
</Custom Execution>
$gameTemp.reserveCommonEvent(15);
$gameVariables.setValue(1, user._actorId);
$gameVariables.setValue(2, skill.id);
</Custom Execution>
Thanks, in advance, for anyone willing to help!