I want to add 1 to [index 2] of an array each time this script runs:
This script keeps track of a record of the largest number for each variable (blue, sky, and cloud) each time it runs. The script works perfectly for the first two index positions of the array, but I'm struggling with adding 1 to the final index position. I've been able to set [index position 2] to 1 (as in the example above to show my progress of working code thus far), but I want to add 1 to the previous value of [index position 2] each time this script runs.
Things I can do:
correctly sets [index position 2] to 5 (2 + 3 = 5), so I can do math here, however if I add 1 to the index position of the variable:
I get NaN returned in [index position 2], which means whatever was/is in $gameVariables.value(119)[2] before I tried adding 1 to it wasn't a number, thus I can't add 1 to "not a number".
What's confused me is that in my code I'm able to check if "blue" is less than or equal to $gameVariables.value(119)[0], so why is $gameVariables.value(119)[0] acting like a number whereas $gameVariables.value(119)[2] isn't the first time this code runs before any of the index positions have any values in them yet?
I've been all over Google, Stack Overflow and these forums for hours (in fact since last night too) looking at examples, but I'm probably trying to do something so super-basic that I'm just not seeing what I'm missing.
As always, thank you everyone for your amazing help. I'm still learning and these forums have been incredible!!
Code:
let blue = Math.round(Math.random() * ((400 - 100) + 100));
if (blue <= $gameVariables.value(119)[0]) {}
else{$gameVariables.setValue(119, [blue,$gameVariables.value(119)[1],$gameVariables.value(119)[2]]);}
let sky = Math.round(Math.random() * ((40 - 10) + 10));
if (sky <= $gameVariables.value(119)[1]) {}
else{$gameVariables.setValue(119, [$gameVariables.value(119)[0],sky,$gameVariables.value(119)[2]]);}
let cloud = 1; // I know this won't add 1 at the moment because this is where I need help.
$gameVariables.setValue(119, [$gameVariables.value(119)[0],$gameVariables.value(119)[1],cloud]);
This script keeps track of a record of the largest number for each variable (blue, sky, and cloud) each time it runs. The script works perfectly for the first two index positions of the array, but I'm struggling with adding 1 to the final index position. I've been able to set [index position 2] to 1 (as in the example above to show my progress of working code thus far), but I want to add 1 to the previous value of [index position 2] each time this script runs.
Things I can do:
Code:
let cloud = 2 + 3;
correctly sets [index position 2] to 5 (2 + 3 = 5), so I can do math here, however if I add 1 to the index position of the variable:
Code:
let cloud = 1 + $gameVariables.value(119)[2];
I get NaN returned in [index position 2], which means whatever was/is in $gameVariables.value(119)[2] before I tried adding 1 to it wasn't a number, thus I can't add 1 to "not a number".
What's confused me is that in my code I'm able to check if "blue" is less than or equal to $gameVariables.value(119)[0], so why is $gameVariables.value(119)[0] acting like a number whereas $gameVariables.value(119)[2] isn't the first time this code runs before any of the index positions have any values in them yet?
I've been all over Google, Stack Overflow and these forums for hours (in fact since last night too) looking at examples, but I'm probably trying to do something so super-basic that I'm just not seeing what I'm missing.
As always, thank you everyone for your amazing help. I'm still learning and these forums have been incredible!!