I so strongly disagree with this because there are so many plugins that I run into that are like this. The documentation takes the time to explain that you can change the entire group, but why not explain how to change one member with a clear example?
I understand where you're coming from, and I do think Yanfly could have been a bit clearer with a line like "where enemy is any reference to a Game_Enemy," but overall the clearly stated presumption is that anyone going directly to the script calls has a working knowledge of JavaScript, in which case they should be able to read the relevant information in the core engine's files.
Try to see this from someone's perspective that's trying to learn what all of the stock (and additional plugin) functions do. How are we supposed to know to use $gameTroop.members()[0], and what is the difference from using $gameTroop._enemies[0]?
By looking at the code -
$gameTroop._enemies is used in precisely four lines in the entire codebase. Two are initializing or resetting it to an empty array, one is pushing the enemies belonging to the troop into that array when the troop is made at the beginning of battle, and the last is inside the getter function you cite below. There are zero places where an enemy is referenced during battle using the
_enemies property.
And, honestly, the last bit should be the only part one
needs to see - if one knows what a getter function is, then one ought to know proper OOP is to always use it. I'm not saying this in any negative way toward you, I'm just responding to your question of how one is supposed to know - it is expected that if you're trying to read/use/modify the code, one has the larger knowledge of the programming language to do so.
I realize many people in this hobby space
don't and have tried to pick up bits and pieces of JavaScript without taking the time to do a proper course of some sort, but then those are the risks one runs choosing that approach.
I'm genuinely asking because while I realize members() is a getter function, MV library states that both return array<Game_Enemy>. Diving into Game Troop also reveals:
Code:
Game_Troop.prototype.members = function() {
return this._enemies;
};
As far as I can tell, it doesn't do anything special?
MV library is not any kind of instructional document telling you what to use, it simply and literally lists all properties of all the data types. So yes, _enemies is the actual array of Game_Enemy and the members() method returns that array of Game_Enemy - that's true of any getter function you ever look at.
And in this case, there isn't anything natively done to the array in the getter function, but it's always best practice to always use one when provided. Plugins you might install could modify members() and there are certainly other getter functions that
do perform operations before returning a value (see the actor version, Game_Party.prototype.members).
The larger point is that we don't pick and choose which getters we think matter or not, it's correct programming habits to always use them when provided.
If I didn't have previous coding knowledge, how do I know how to select Enemy 1, 2, or 3? It doesn't tell me.
Again, Yanfly's Lunatic Mode section is pretty clearly marked as for people who have JavaScript experience. You're not wrong, he
could have included detailed instructions - either there or in another universal section of his Web site - but he chose not to, and simply provided the script calls for those who have previous coding knowledge.
This is better than many other authors do (see the number of threads having problems because VisuStella plugins provide almost zero of their internal script calls for reference).
So I guess the answer to your question is, "if you didn't have previous coding knowledge, how do you know...?" You either study JavaScript to gain that knowledge, or you ask someplace like here in a Learning JavaScript or Plugin Support thread to get some advice and examples of how the script calls can be practically used.
Sure, I can use $gameTroop.members()[0].changeLevel = x to change that value
Just as a small pedantic note, you can't - it would be
$gameTroop.members()[0].changeLevel(x) - but I understand that's not your point
😉
but the documentation doesn't say that anywhere. Is this even the intended way to do it?
I don't think there's any "intent" behind a line of code. It's there, it tells you what it does, you use it in whatever way you find a use for in your game.
I hope that was somewhat helpful to your questions - I understand "take JavaScript classes or do tutorials" is not the answer many people want to hear when asking for what they think should be basic RPG Maker/plugin help. But the fact is you can do a ton with MV as a whole and plugins like this without ever touching script calls, so you're not going to find plugins that give you the functions and a little tutorial on how you can use them.
You either know how or you're very welcome to ask for help whenever you need.