Actors turning into Objects

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I have a script snippet that loops through $dataActors and builds an array of all actors who are not currently in the party.


Each $dataActor element is an Object, so I convert it into a Game_Actor object in order to do the comparision and add to the array.  But when it's all done, the array is full of elements of type Object, not Game_Actor.  Can't figure out what I'm doing wrong.


Game_Party.prototype.getNonPartyActors = function() {
var tempActors = $dataActors.filter(function(actor) {
if (!actor) return null;
// at this point, actor exists and is of type Object
actor = $gameActors.actor(actor.id);
// now actor is type Game_Actor
if ($gameParty.members().indexOf(actor) < 0) {
return actor;
// actor is still a Game_Actor here
}
}.bind(this));
if (tempActors.length > 0) {
// now tempActors is filled with elements of type Object, not Game_Actor
...
}
};




I wondered if it was because I was using the same variable name, so I changed it to use two different variables for the $dataActors object and the $gameActors object.  Still get the same results.


Edit: okay - it's because I'm using filter I think.  Changed it to map instead, but now it's including null elements.  I'm just going to change it to a regular forEach loop and be done with it, as I'm not sure there's a way to do it like I want, unless I do a filter AND a map.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,051
Messages
1,018,549
Members
137,836
Latest member
T62352536256t362
Top