Cannot read property 'battleMembers' of null

I opened a new topic because this is a completely different question/problem.

I can't understand, or find, for the life of me why this is undefined. Can anyone help please? What is the proper way to call these variables/functions/arrays?

I'm getting the error:

Cannot read property 'battleMembers' of null

(function() { Eilios.Parameters = PluginManager.parameters('Eilios_Movement'); Eilios.Param = Eilios.Param || {}; Eilios.Param.CriticalMultiplier = Number(Eilios.Parameters['Critical Multiplier']); Eilios.Param.MaxInitialTP = Number(Eilios.Parameters['Max Initial TP']); Eilios.Param.MinInitialTP = Number(Eilios.Parameters['Min Initial TP']); // set up vars to store the old x,y var originPartyXY = {}; var tempArray = {}; // set the initial offset Game_Party.prototype.setXYOffset = function() { // loop through each party member var pCount = 0; for (pCount = 0; pCount < $gameParty.battleMembers().length - 1; pCount++) { // save the original xy into main array, reset temp array each time tempArray = {}; tempArray.push($gameParty.battleMembers()[pCount].x); tempArray.push($gameParty.battleMembers()[pCount].y); originPartyXY.push(tempArray); if (pCount % 2) { // set the new xy $gameParty.battleMembers()[pCount].x += -2; $gameParty.battleMembers()[pCount].y += $gameParty.battleMembers()[pCount - 1].y + 2; }else{ // set the new xy $gameParty.battleMembers()[pCount].x += 2; $gameParty.battleMembers()[pCount].y += $gameParty.battleMembers()[pCount - 1].y + 2; } } // show results console.log("made it to the function!"); }; Game_Party.prototype.setXYOffset();})();Looking through other plugins it seems people can just use this:

// Local Functions - Get Action Skills function ActionSkill_GetActionSkills() { var ActiveMembersArr = $gameParty.battleMembers(); var ActiveMembersSkills = []; for (i = 0; i < ActiveMembersArr.length; i++) { // Check all Active Party Members for (j = 0; j < ActiveMembersArr._skills.length; j++) { var skill = $dataSkills[ActiveMembersArr._skills[j]]; // Tag Check for any usable Skills if (TagCheck(skill, ActionSkillTag)) { if (!ActiveMembersSkills.contains(ActiveMembersArr._skills[j])) ActiveMembersSkills.push(ActiveMembersArr._skills[j]); } } } // Return the Skills found return ActiveMembersSkills; }So I'm pretty lost. I'm new to rmmv, not new to programming. Not an expert with javascript but this seems it just isn't accessing the variable/array at all....................
It is saying $gameParty is not defined.  Looks like it's trying to run the command before the DataManager has set up the game objects.


This:


Game_Party.prototype.setXYOffset();


is not how you apply the command.  This is:


$gameParty.setXYOffset();


and needs to be done within a method that's called at some point after DataManager has set up the game objects.
and needs to be done within a method that's called at some point after DataManager has set up the game objects.
This indeed.

You're calling your method as soon as your plugin is loaded. There's no $gameParty yet at that point.

You'll want to call it, for example, inside something like Scene_Battle.prototype.start.
It is saying $gameParty is not defined.  Looks like it's trying to run the command before the DataManager has set up the game objects.

This:

Game_Party.prototype.setXYOffset();

is not how you apply the command.  This is:

$gameParty.setXYOffset();

and needs to be done within a method that's called at some point after DataManager has set up the game objects.

This indeed.

You're calling your method as soon as your plugin is loaded. There's no $gameParty yet at that point.

You'll want to call it, for example, inside something like Scene_Battle.prototype.start.

I see what you mean, I just don't know how to do it. What can I throw this stuff in that I want to start off the bat after the game objects have loaded? This is, eventually, my attempt to change the follow path of the party members, so it would have to do be done right after load.

Edit:

I put it in Scene_Battle.prototype.start {}, but that's when it switches to a battle scene yes? I need it to be when the game turns on, after selecting new game or continuing a game. I wish there was API. 🙁

Edit 2:

I tried:

Scene_Map.prototype.onMapLoaded = function() { $gameParty.setXYOffset();};but I immediately get an error, obviously, right before loading the game, that says:

TypeError

undefined is not a function
Edit 2:
I tried:

Scene_Map.prototype.onMapLoaded = function() { $gameParty.setXYOffset();};but I immediately get an error, obviously, right before loading the game, that says:

TypeError

undefined is not a function
What lines are you getting this error? You can check that by pressing F8 to open the console.

I imagine you're getting them in those lines:

tempArray.push($gameParty.battleMembers()[pCount].x);tempArray.push($gameParty.battleMembers()[pCount].y);originPartyXY.push(tempArray);You're using ".push" in variables that you defined as objects, by initializing them as {}. You'd want them to be arrays, [].

Change those:

var originPartyXY = {};var tempArray = {};// (...)tempArray = {};To

var originPartyXY = [];var tempArray = [];// (...)tempArray = [];You'll also get another error later on, because you're trying to check the .y property of $gameParty.battleMembers()[-1] when you first run through that loop.
What lines are you getting this error? You can check that by pressing F8 to open the console.

I imagine you're getting them in those lines:

tempArray.push($gameParty.battleMembers()[pCount].x);tempArray.push($gameParty.battleMembers()[pCount].y);originPartyXY.push(tempArray);You're using ".push" in variables that you defined as objects, by initializing them as {}. You'd want them to be arrays, [].

Change those:

var originPartyXY = {};var tempArray = {};// (...)tempArray = {};To

var originPartyXY = [];var tempArray = [];// (...)tempArray = [];You'll also get another error later on, because you're trying to check the .y property of $gameParty.battleMembers()[-1] when you first run through that loop.

PHP mixes oppppsss. 🙂

The error is before the map even loads. It's just a black screen.

Edit: That did fix it though, now I'm getting other errors about:

'TypeError: Cannot read property 'y' of undefined

    at Game_Party.setXYOffset (/C:/x/x/x/x/x/js/plugins/Eilios_Movement.js:63)'

 

but it's because $gameParty.battleMembers()[1].x is undefined, can't get the x that way in this scenario, so you still helped immensely, plus I learned I can scan through like everything in the console, so thank you!!!!!! Hopefully this is the end of my problems.

 

🙂

Original thread: https://forums.rpgmakerweb.com/threads/cannot-read-property-battlemembers-of-null.51007/