Conditional Commands

So, I'm not entirely sure whether or not this is even possible, but how would I go about showing certain commands in a window only when a condition is fulfilled (i.e. if a variable is equal to 2, show a certain command, but when that variable equals 3, show a different command)? I'm trying to set up a phone-type system where the player can get texts from NPCs, and the texts are sorted according to the NPC selected.


Here's a screenshot of the interface I have so far, in case that's any more helpful:

Spoiler
send help.PNG



Any advice is much appreciated!
A copy of your script would be more useful than a screenshot of the interface.


MV already has a number of menus that show options only if certain conditions are met.  Look at those and see how they are done.  You'll just substitute your own conditions.  The main menu is one, because it checks if the System tab has boxes checked for allowing skills, equip, etc.
A copy of your script would be more useful than a screenshot of the interface.

...Yep. Sorry about that.


Here's the relevant chunk of code that I'm currently puzzling over:

Spoiler
//----------------
//Window_Texts
//----------------
function Window_Texts(){
this.initialize.apply(this, arguments);
}

Window_Texts.prototype = Object.create(Window_Command.prototype);
Window_Texts.prototype.constructor = Window_Texts;

Window_Texts.prototype.initialize = function(){
Window_Command.prototype.initialize.call(this, 300, 320);
};

Window_Texts.prototype.maxCols = function(){
return 2;
};

Window_Texts.prototype.windowWidth = function(){
return Graphics.width - 300;
};

Window_Texts.prototype.windowHeight = function(){
return Graphics.height - 320;
};

Window_Texts.prototype.drawTexts = function(fromContact){

for (var i = 0; i < $dataIMs.length; i++){
if (!$gameSystem._ims) continue;
if ($gameSystem.hasMessage(i)){
var im = $gameSystem.getIM(i);
var imFrom = im.From;
if (imFrom == fromContact) {
var cmdText = im.Subject;
this.addCommand(cmdText);
}
}
}

};


drawTexts gets called in this scene:



//--------------
//Scene_Cellphone
//--------------

function Scene_Cellphone(){
this.initialize.apply(this, arguments);
}

Scene_Cellphone.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Cellphone.prototype.constructor = Scene_Cellphone;

Scene_Cellphone.prototype.initialize = function(){
Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Cellphone.prototype.start = function(){
Scene_MenuBase.prototype.start.call(this);
this.drawWindows();
this.setWindowHandlers();
};

Scene_Cellphone.prototype.drawWindows = function(){
this.oldIndex = -1;
this._contactWindow = new Window_ContactSelect();
this._contactInfo = new Window_ContactInfo();
this._cellTitle = new Window_CellTitle();
this._intTitle = new Window_InterestTitle();
this._texts = new Window_Texts();

this.addWindow(this._contactWindow);
this.addWindow(this._contactInfo);
this.addWindow(this._cellTitle);
this.addWindow(this._intTitle);
this.addWindow(this._texts);
};

Scene_Cellphone.prototype.setWindowHandlers = function(){
this._contactWindow.setHandler('phonecall', this.commandPhone.bind(this));
};

Scene_Cellphone.prototype.commandPhone = function(){
var varid = $gameSystem.contIDvar;

$gameVariables.setValue(varid, this.SelectedContact);
this.popScene();
$gameTemp.reserveCommonEvent(9);
};

Scene_Cellphone.prototype.update = function(){
Scene_MenuBase.prototype.update.call(this);

var index = this._contactWindow.index();
var cmdName = this._contactWindow.commandName(index);

if (index != this.oldIndex){
for (var i = 0; i < $dataContacts.length; i++){
if (!$gameSystem._contacts) continue;
if ($gameSystem.getContact(i).Name != cmdName){
continue;
} else {
var contact = i;
break;
}
}
this.SelectedContact = contact;
this._contactInfo.drawContactInfo(contact);
this._texts.drawTexts(contact);
}
this.oldIndex = index;

if (Input.isTriggered('cancel')){
SoundManager.playCancel();
this.popScene();
}
};


Why didn't I post this before? I feel pretty dumb.



I've been looking through the MV menus, and they seem to be doing the same thing in terms of, say, checking a condition and adding that command, but it's still not working for me...which leads me to believe the error is on my end.
your script will be very helpful for me to understand, since i wanted to create a phone menu but didnt know how to

Original thread: https://forums.rpgmakerweb.com/threads/conditional-commands.72510/