Conditional Commands

AcerK

Muse of Ink
Member
Joined
Dec 20, 2012
Messages
19
Reaction score
16
First Language
English
Primarily Uses
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:

send help.PNG



Any advice is much appreciated!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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.
 

AcerK

Muse of Ink
Member
Joined
Dec 20, 2012
Messages
19
Reaction score
16
First Language
English
Primarily Uses
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:

//----------------
//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.
 

Ash009

Warper
Member
Joined
Jun 17, 2016
Messages
3
Reaction score
0
First Language
english
Primarily Uses
your script will be very helpful for me to understand, since i wanted to create a phone menu but didnt know how to
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top