Howdy y'all!
I'm learning how to do code with MV and I've come across this basic For Loop that I THINK I'm reading correctly but if I am then the logic seems weird to me, so I'm hoping someone here can help me to understand it all better.
The For Loop is this:
And the logic as I understand it is that what it's doing is:
> variable x is set to the length of the array of Party Members.
> variable i is set to 0
> if i is less than x
> then gain party member i's HP by 9999 and add 1 to the value of variable i
> do this all again and stop after i is equal to x
But what I don't understand is why Party Member [0] also gets healed.
Shouldn't this happen in a party of 4 instead?:
i equals 0, x equals 3, add 1 to i, i now equals 1, heal party member i (aka 1) 9999
This would skip Party Member [0] but it's how the code reads to me because the adding of the 1 comes a line before the gaining of the HP.
So I'm struggling to understand why the Healing takes place before the Adding 1 to the value i, as I've tested this code and it DOES in fact heal all 4 Party Members without skipping any.
Any light or clarity y'all can shed on this matter is GREATLY appreciated!
I'd love to be able to do all this coding stuff, and RPG Maker has always been a fun engine to build things in for me.
I'm learning how to do code with MV and I've come across this basic For Loop that I THINK I'm reading correctly but if I am then the logic seems weird to me, so I'm hoping someone here can help me to understand it all better.
The For Loop is this:
var x = $gameParty.members().length;
for (i = 0; i < x; ++i) {
$gameParty.members()[i].gainHp(9999);
}And the logic as I understand it is that what it's doing is:
> variable x is set to the length of the array of Party Members.
> variable i is set to 0
> if i is less than x
> then gain party member i's HP by 9999 and add 1 to the value of variable i
> do this all again and stop after i is equal to x
But what I don't understand is why Party Member [0] also gets healed.
Shouldn't this happen in a party of 4 instead?:
i equals 0, x equals 3, add 1 to i, i now equals 1, heal party member i (aka 1) 9999
This would skip Party Member [0] but it's how the code reads to me because the adding of the 1 comes a line before the gaining of the HP.
So I'm struggling to understand why the Healing takes place before the Adding 1 to the value i, as I've tested this code and it DOES in fact heal all 4 Party Members without skipping any.
Any light or clarity y'all can shed on this matter is GREATLY appreciated!
I'd love to be able to do all this coding stuff, and RPG Maker has always been a fun engine to build things in for me.