communicating with choices callback

I'm building a choices list of party characters depending on a particular status

for (i=0;i<4;i++) {
var ai = $gameParty._actors;
var actor = $gameActors.actor(ai);
states = actor._states; // naughty ?
for (state in states) {
if (states[state]=="1") {
choices.push(actor.name());
count++;
}
}
}


the callback is like this
params.push();
$gameMessage.setChoiceCallback(function(n) {
console.log("n="+n);
}.bind(this));

however in the callback function I think I'm right in thinking all you get is the index of the selected choice

is there any way to communicate other info connected with that choice, or will I have to build a filtered array (matching the choices) in the callback function and use the index to select the info I'm after
I'm building a choices list of party characters depending on a particular status



the callback is like this


however in the callback function I think I'm right in thinking all you get is the index of the selected choice

is there any way to communicate other info connected with that choice, or will I have to build a filtered array (matching the choices) in the callback function and use the index to select the info I'm after

logicly you make callBack in a variable

PHP:
var myCallBack = function(n){
// stuff
}.bind(this);

$gameMessage.setChoiceCallback(myCallBack);

of use a closure with return, for store what you need in the function closure

PHP:
var myCallBack = (function(n){
  var n = n;
  return function(n){ '//stuff' }.bind(this)
})();
$gameMessage.setChoiceCallback(myCallBack);

https://forums.rpgmakerweb.com/index.php?threads/functional-programming-adventure-closures.81115/
how does this help?
LMAO - its been a few years since I did much JavaScript, I'd forgotten how broken its variable scoping is... I can just access variables outside the function...
LMAO - its been a few years since I did much JavaScript, I'd forgotten how broken its variable scoping is... I can just access variables outside the function...
if you call call scripts, in the rmmv boxes, it becomes much more complicated.
The scope becomes difficult to manage, you have to create a closure or also create a global variable obj to store your valur.

If you code are in a .js file ,
it's more easy to manage your scope.
It depends on how you want to code your project.

I'm not very fan of putting scripts in rmmv windows,

Original thread: https://forums.rpgmakerweb.com/threads/communicating-with-choices-callback.86985/