Hi everyone! First post! Nice to meet you all! I'm new to JS/coding, so apologies if there are any mistakes.
I have set one of my game variables to an array. I have two questions:
1) How can I add/subtract from one element within an array?
For example, if I wanted to subtract five from index zero so that this:
would become this:
2) How can I add/subtract a number from ALL of the elements of in my array?
For example, if I wanted to subtract five from EACH element so that this:
would become this:
Thank you in advance!
EDIT:
Apologies, but after tinkering around more with it I think I have figured it out. It might not be the cleanest code,
For number one I solved it with something like this:
For number 2:
If there is a better/cleaner way to do this, feel free to let me know, but this has been working for now.
I have set one of my game variables to an array. I have two questions:
1) How can I add/subtract from one element within an array?
For example, if I wanted to subtract five from index zero so that this:
JavaScript:
$gameVariables.value(22) = [10, 11, 12];
would become this:
JavaScript:
$gameVariables.value(22)= [5, 11, 12];
2) How can I add/subtract a number from ALL of the elements of in my array?
For example, if I wanted to subtract five from EACH element so that this:
JavaScript:
$gameVariables.value(22) = [10, 11, 12];
would become this:
JavaScript:
$gameVariables.value(22)= [5, 6, 7];
Thank you in advance!
EDIT:
Apologies, but after tinkering around more with it I think I have figured it out. It might not be the cleanest code,
For number one I solved it with something like this:
JavaScript:
var numberarr = [1, 2, 3, 4, 5, 6, 7, 8]
var numberarr2 = numberarr.map( function(value) {
return value - 1;
} );
var numberarr = numberarr2
$gameVariables.setValue(22, numberarr);
For number 2:
Code:
var holder = $gameVariables.value(22)[1] + 100;
$gameVariables.value(22)[1] = holder;
If there is a better/cleaner way to do this, feel free to let me know, but this has been working for now.