Hi Everyone,
I'm am just getting into development with RMMV and despite having some background with development in other languages, I'm finding some aspects of Javascript difficult to wrap my head around. I've been struggling with a problem that seems like it should be a relatively simple to solve for, but I'm at an impasse, possibly because I'm not understanding fundamental about the language, but also probably because I can't understand the syntax of what's being done. I'm hoping someone might be willing to give me some guidance.
I am working on some code that will trigger during battles where a random party member might say a random message for a bit of spontaneous color during battles. The party leader remains silent, so the very first check I want to undertake is what is the number of actors in the party. Reviewing the out-of-the box code, it seems like it should be simple, based on the code I've written the following function:
However, when I call it, it returns a TypeError of "Cannot read property 'map' of undefined". Following the Game_Party.prototype.size function, it calls Game_Party.prototype.members, which in turn calls Game_Party.prototype.allMembers, which is where the dev tools indicate we are having the problem. So, that far I seem to be okay with what's going, but when it comes time to evaluate allMembers, I'm feeling less confident, specifically the portion in red:
What I interpret this as being intended to do is going through the list of actors in the Game_Party and returning an array of those who are currently in the party, but the .map command in JavaScript is a new concept to me. From what I can understand of more general documentation is that it needs to be called on an array and this error suggests that I've passed it an empty one and I'm afraid I don't know my tool belt well enough to check that.
So, in so many words (A lot, in fact), here are my questions:
- How would I check the array being used in the allMembers function?
- Are there any thoughts on why I would be passing an empty array in the first place? It all seems to be out-of-the-box code, so I would think it would work on the Game_Party object which I thought would be initialized.
- Lastly, am I totally off course and there's an obvious way to check the party size that I'm missing?
Wow... That was a lot. Apologies for going on like that. If anyone has any thoughts they would be willing to share, I would really appreciate it. Thanks 😀
I'm am just getting into development with RMMV and despite having some background with development in other languages, I'm finding some aspects of Javascript difficult to wrap my head around. I've been struggling with a problem that seems like it should be a relatively simple to solve for, but I'm at an impasse, possibly because I'm not understanding fundamental about the language, but also probably because I can't understand the syntax of what's being done. I'm hoping someone might be willing to give me some guidance.
I am working on some code that will trigger during battles where a random party member might say a random message for a bit of spontaneous color during battles. The party leader remains silent, so the very first check I want to undertake is what is the number of actors in the party. Reviewing the out-of-the box code, it seems like it should be simple, based on the code I've written the following function:
Game_Party.prototype.partyLargerThanHero = function()
{
return this.size() > 1;
}
However, when I call it, it returns a TypeError of "Cannot read property 'map' of undefined". Following the Game_Party.prototype.size function, it calls Game_Party.prototype.members, which in turn calls Game_Party.prototype.allMembers, which is where the dev tools indicate we are having the problem. So, that far I seem to be okay with what's going, but when it comes time to evaluate allMembers, I'm feeling less confident, specifically the portion in red:
Game_Party.prototype.allMembers = function() {
return this._actors.map(function(id) {
return $gameActors.actor(id);
});
};
What I interpret this as being intended to do is going through the list of actors in the Game_Party and returning an array of those who are currently in the party, but the .map command in JavaScript is a new concept to me. From what I can understand of more general documentation is that it needs to be called on an array and this error suggests that I've passed it an empty one and I'm afraid I don't know my tool belt well enough to check that.
So, in so many words (A lot, in fact), here are my questions:
- How would I check the array being used in the allMembers function?
- Are there any thoughts on why I would be passing an empty array in the first place? It all seems to be out-of-the-box code, so I would think it would work on the Game_Party object which I thought would be initialized.
- Lastly, am I totally off course and there's an obvious way to check the party size that I'm missing?
Wow... That was a lot. Apologies for going on like that. If anyone has any thoughts they would be willing to share, I would really appreciate it. Thanks 😀