I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.
Take a look at how Game_Interpreter does it, in particular "$game_message.setChoiceCallback()":
Game_Interpreter.prototype.setupChoices = function(params) {
var choices = params[0].clone();
var cancelType = params[1];
var defaultType = params.length > 2 ? params[2] : 0;
var positionType = params.length > 3 ? params[3] : 2;
var background = params.length > 4 ? params[4] : 0;
if (cancelType >= choices.length) {
cancelType = -2;
}
$gameMessage.setChoices(choices, defaultType, cancelType);
$gameMessage.setChoiceBackground(background);
$gameMessage.setChoicePositionType(positionType);
$gameMessage.setChoiceCallback(function(n) {
this._branch[this._indent] = n;
}.bind(this));
};
"n" in this case is the choice window's selected index.
So, I've tested it out using 'console.log(n)' and I see that it's giving me the index number of the choice. The only problem is when I'm trying to put text on the screen after the choice like this:
options=["One","Two"];
$gameMessage.setChoices(options, 0, -1);
$gameMessage.setChoiceCallback(function(n) {
if (n==0) {$gameMessage.add("You chose one")} else {$gameMessage.add("You chose two")};
});
It just ends without the text being shown.
Is there any particular reason why you can't just call a common event?