Help on my simple "Check for Party Formation Change" Plugin

Hello Forum,

bloody Javascript MV Plugin Noob here.
Basically im working on my first plugin fitted for only my game.

My goal:
Whenever a Party formation within the Game Menu occurs, change Variable 41 to Party Leader's Actor ID.

I copied the function of the Scene_Menu, when the formation function is applied.
I aliased it to "check_if_formation_change" in order to avoid overriding the original and set PluginManager.parameters
to add my Plugin to the game.

Then I simply added $gameVariables._data[41] = $gameParty._actors[0]; in the condition for
when party formation change is initiated.

I also of course added the plugin to the Plugins in MV.
But when I check the Variable 41 ingame, after a party formation change, it remains undefined, therefore it didn't work.

I appreciate anybody who goes through the first troubles of a bloody js noob.
Thank you in advance!

My plugin so far:

(function() {
var parameters = PluginManager.parameters('SetFormationChangeToVar');

check_if_formation_change = Scene_Menu.prototype.onFormationOk;

Scene_Menu.prototype.onFormationOk = function() {
var index = this._statusWindow.index();
var actor = $gameParty.members()[index];
var pendingIndex = this._statusWindow.pendingIndex();
if (pendingIndex >= 0) {
$gameParty.swapOrder(index, pendingIndex);
this._statusWindow.setPendingIndex(-1);
this._statusWindow.redrawItem(index);
$gameVariables._data[41] = $gameParty._actors[0];
} else {
this._statusWindow.setPendingIndex(index);
}
this._statusWindow.activate();
};

})
Game variables is a mess to work with in code 😅

You'll have to use the setValue function:
JavaScript:
$gameVariables.setValue(41, $gameParty._actors[0])
Game variables is a mess to work with in code 😅

You'll have to use the setValue function:
JavaScript:
$gameVariables.setValue(41, $gameParty._actors[0])

Thank you for responding so quickly.
I corrected the line and added the line to several other conditions, just to see if anything would make a change, but unfortunately still nothing happens to Variable 41.

/EDIT: Maybe I took the wrong Formation function, but it seems to be the right one.
The code for get the Id of the party leader is that:
$gameParty.leader().actorId()
So you have to set:
$gameVariables.setValue(42, $gameParty.leader().actorId())

And for the check, if the formation changes, if your point only tracks the party leader, you can check only the party leader Id:
If($gameParty.leader().actorId() === $gameVariables.value(41)) {
It's equal, so the leader doesn't change.}else{ it's not equal. So let's assign the variable value 41 to the party leader id again}
The code for get the Id of the party leader is that:
$gameParty.leader().actorId()
So you have to set:
$gameVariables.setValue(42, $gameParty.leader().actorId())

And for the check, if the formation changes, if your point only tracks the party leader, you can check only the party leader Id:
If($gameParty.leader().actorId() === $gameVariables.value(41)) {
It's equal, so the leader doesn't change.}else{ it's not equal. So let's assign the variable value 41 to the party leader id again}


I changed the line as you suggested. However, I didn't make a conditional statement out of it, because for now I want to keep it as simple as possible, to see where the problem lies.
Unfortunately, it still did not change anything. Ingame Variable 41 still does not change after formation change.

I also put the plugin on the very top of the list in the manager, to avoid any cross-conflict with other plugins.

It's hard to remember when to use $gameVariables._data[x] or $gameVariables.value(x).
That's really confusing. :LZYdizzy:
That is strange. Try to put below the gameVariables:
console.log($gameVariables.value(42)) and see what the console will show to you.

I think you should stick with this:
To return a value - $gameVariables.value(ID)
To set a value - $gameVariables.setValue(ID, value).

I'm not in my computer otherwise I will give it a try.
But why you have to check the formation change?
If I was you, I will add the value to the variable only when menu closes, instead of using the function FormationOk.
Do you have 42 variables in the variables list? Trying to set a game variable that doesn't exist will always set it to undefined.
That is strange. Try to put below the gameVariables:
console.log($gameVariables.value(42)) and see what the console will show to you.

I think you should stick with this:
To return a value - $gameVariables.value(ID)
To set a value - $gameVariables.setValue(ID, value).

I'm not in my computer otherwise I will give it a try.
But why you have to check the formation change?
If I was you, I will add the value to the variable only when menu closes, instead of using the function FormationOk.


The line $gameVariables.setValue(41, $gameParty.leader().actorId()); definetly works, I tried it in the rpg_scenes.js, however I did not want to mess with the original js files, therefore a plugin.

I think the problem lies somewhere in MV reading the plugin correctly. It is apparently ignoring my plugin and still using it's original Formation Change function.

Is there a difference when I check the formation during the formation function or when menu closes?
Is it easier to make a "Check when menu closes" plugin?
Do you have 42 variables in the variables list? Trying to set a game variable that doesn't exist will always set it to undefined.

Yes, the variable definetly exists and the existing Variables is currently set to 100.
Aaah I see the problem now, your plugin is an anonymous function but you don't call it after!

Add () to line 26 so it's })()
Aaah I see the problem now, your plugin is an anonymous function but you don't call it after!

Add () to line 26 so it's })()


Genius!
It worked! Wow, my first plugin, thanks to you guys! Thats .... magical :LZSblush:

Original thread: https://forums.rpgmakerweb.com/threads/help-on-my-simple-check-for-party-formation-change-plugin.120807/