I had a spot of bother with this script that I've managed to get around, and I thought I'd share it in case anyone else is in a similar spot.
I found that after adding Khas Core 2.0 to my project, some scripts that I wrote myself with totally unrelated functions broke. I eventually pinned down the part of Khas Core that was giving me grief, and it's this bit at the start:
JavaScript:
Array.prototype.remove = function(value) {
var index = this.indexOf(value);
if (index != -1) {
this.splice(index, 1);
};
};
Array.prototype.include = function(value) {
return this.indexOf(value) > -1;
};
This was blowing up my functions that looked like this:
JavaScript:
for (x in this.members()) {
var actor = this.members()[x];
if (actor.getGrowthLevels() > 0) {
return true;
}
}
What was happening was, "for...in" iterates through all the properties of an object. Normally, $gameParty.members() just has an array of actors in it which I'd iterate through, BUT, when all arrays have the remove and include functions added to them in Khas Core, these are considered properties, and they're iterated through as well. Eventually my code was trying to call "this.members()[include].getGrowthLevels()", which was blowing up because "this.members()[include]" is total nonsense.
After a whole load of reading and advice from friends I found I shouldn't be using "for... in" for iterate through arrays, but "for... of". This is how my code looks now, fixed:
JavaScript:
for (var actor of $gameParty.members()) {
if (actor.getGrowthLevels() > 0) {
return actor;
}
}
So, don't use "for... in" to iterate through arrays!
However, I must say, I'm not wild about Khas Core adding methods in array.prototype, especially with generic names like "include" and "remove". This impacts every other script in a project that uses arrays, which is likely most scripts. If another script writer also decides to extend array.prototype with include & remove, it could cause major headaches.
I appreciate that array.include and array.remove are really useful (I see there's discussion a couple years ago about adding them to Ecmascript:
https://esdiscuss.org/topic/array-prototype-remove-item ) but making these additions as part of a script just seems very very risky?
Well, anyway, I've shared my experience. Thank you so much for the scripts because the lighting effects are incredibly cool looking!