Script works, but not in a Conditional. Explanation, please..?

Dad3353

Veteran
Veteran
Joined
Mar 9, 2016
Messages
421
Reaction score
109
First Language
English
Primarily Uses
Good evening...


I have the following Script triggered in an Event, which works...

◆Script:$gameMessage.setFaceImage('Actor1',0)     
:      :$gameMessage.setBackground(0)
:      :$gameMessage.setPositionType(2)                   
:      :$gameMessage.add(" Player chose 'Hmm...'")

When  trigger this, I get a Message Box with the Text in it. Good.


I would like to have the same result as part of a Script triggered in an Event, but subject to a Condition. Here's what I have...

◆Script:$gameMap._interpreter.setupChoices([['Yes', 'No', 'Perhaps', 'Certainly', 'Never..!', 'What..?', 'Dunno', 'Hmm...'], 1]);
◆Script:$gameMessage.setChoiceCallback(function(responseIndex) {
:      :  if (responseIndex === 0) {$gameTemp.reserveCommonEvent(28);}if (responseIndex === 1) {$gameTemp.reserveCommonEvent(29);}
:      :  if (responseIndex === 2) {$gameTemp.reserveCommonEvent(30);}if (responseIndex === 3) {$gameTemp.reserveCommonEvent(31);}
:      :  if (responseIndex === 4) {$gameTemp.reserveCommonEvent(32);}if (responseIndex === 5) {$gameTemp.reserveCommonEvent(33);}
:      :  if (responseIndex === 6) {$gameTemp.reserveCommonEvent(34);}
:      :  if (responseIndex === 7) {$gameMessage.setFaceImage('Actor1',0);     
:      :$gameMessage.setBackground(0);
:      :$gameMessage.setPositionType(2);
:      :$gameMessage.add(" Player chose 'Hmm...'");}
:      :});

The first seven choices work,by calling a Common Event each. It's the last one that I can't get to work. If I have it call a Common Event like the others, it works fine. How, though, to have the Message Box directly in the Script, without calling a Common Event..? With the Script above, there is no error flagged, but no Message Box, either.


Thanks in advance for pointing me in the right direction.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,395
Reaction score
3,245
First Language
Java's Crypt
Primarily Uses
RMMV
Ah, now I understand the issue.


The problem here is that when you choose your option, the game clears all the messages on $gameMessage, so adding anything to it in that callback is useless.


When you reserve a common event, it is only called in the next game frame, way after the $gameMessage.clear is called, that's why it works.
 

Dad3353

Veteran
Veteran
Joined
Mar 9, 2016
Messages
421
Reaction score
109
First Language
English
Primarily Uses
@Hudell...


Thanks for that, it's good to know. It provokes, of course, the next question... How, then to have a Message Box displayed. Would a 'Wait' allow time to pass to re-create a Game Message, or is there some other necromancy needed..? Is it just the fact that I'm using Game Message that's wrong..? I suppose if I'd have chosen a Sound Effect instead, it would have worked, directly in the original Script..? It's all very confusing to the dimly initiated, but the fog is (slowly...) lifting, just the same.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,395
Reaction score
3,245
First Language
Java's Crypt
Primarily Uses
RMMV
Yes, anything that didn't involve $gameMessage would have worked. A quick (and ugly) workaround would be to do this:


setTimeout(function(){
$gameMessage.add('Something');
}, 1);


This would cause the message to be added at least 1 millisecond later. It would actually be executed between the current frame and next one, so it would also happen after the $gameMessage.clear.
 

Dad3353

Veteran
Veteran
Joined
Mar 9, 2016
Messages
421
Reaction score
109
First Language
English
Primarily Uses
@Hudell...


Yay..! I finally got this to work, with the Hero Face and all..! Many thanks; I've learned a lot (most especially the pernickerty nature of js concerning Brackets, Braces and more..!). Somewhat academic, maybe, as the standard Commands are easier to handle, but will surely be useful. Cheers. Here's the code I finally used...

◆Script:$gameMap._interpreter.setupChoices([['Yes', 'No', 'Perhaps', 'Certainly', 'Never..!', 'What..?', 'Dunno', 'Hmm...'], 6]);
◆Script:$gameMessage.setChoiceCallback(function(responseIndex) {
:      :  if (responseIndex === 0) {$gameTemp.reserveCommonEvent(28);}if (responseIndex === 1) {$gameTemp.reserveCommonEvent(29);}
:      :  if (responseIndex === 2) {$gameTemp.reserveCommonEvent(30);}if (responseIndex === 3) {$gameTemp.reserveCommonEvent(31);}
:      :  if (responseIndex === 4) {$gameTemp.reserveCommonEvent(32);}if (responseIndex === 5) {$gameTemp.reserveCommonEvent(33);}
:      :  if (responseIndex === 6) {$gameTemp.reserveCommonEvent(34);}
:      :  if (responseIndex === 7) {setTimeout(function(){
:      :$gameMessage.setFaceImage('Actor1',0);
:      :$gameMessage.setBackground(0);
:      :$gameMessage.setPositionType(2);
:      :$gameMessage.add(" Player chose 'Hmm...'");}, 1);}
:      :});



'Ugly', you say..? Would you care to elaborate on that, and give some indication as to any drawbacks to this..? Does this infringe the 'rules' of js, or will it simply alter the time and space continuum..?
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,395
Reaction score
3,245
First Language
Java's Crypt
Primarily Uses
RMMV
It's just that it is a workaround that shouldn't be needed in the first place.


Try adding this as a plugin:



(function(){
Window_ChoiceList.prototype.hudell_old_callOkHandler = Window_ChoiceList.prototype.callOkHandler;
Window_ChoiceList.prototype.hudell_old_callCancelHandler = Window_ChoiceList.prototype.callCancelHandler;

Window_ChoiceList.prototype.callOkHandler = function() {
var callback = $gameMessage._choiceCallback;
var index = this.index();

this._messageWindow.terminateMessage();
this.close();

if (callback) {
callback(index);
}
};

Window_ChoiceList.prototype.callCancelHandler = function() {
var callback = $gameMessage._choiceCallback;
var index = $gameMessage.choiceCancelType();

this._messageWindow.terminateMessage();
this.close();

if (callback) {
callback(index);
}
};
})();


I didn't test it, but it changes the game to execute the choice callback after the $gameMessage object is cleared, so it might just work without the setTimeout.
 

Dad3353

Veteran
Veteran
Joined
Mar 9, 2016
Messages
421
Reaction score
109
First Language
English
Primarily Uses
Thanks for that; I'll try it out and see where it leads me. Plug-ins, you see, are still 'Dark Matter' to me, so I'm more than wary of even using them, let alone creating or modifying them..! That being said, I've already dipped my virtual toe into those murky waters, having added a series of 'required files' to a Plug-in that had neglected to do so, and I've a couple of very modest experiments 'on the go'. I'll add this to the 'To do' list, mostly for its pedagogic value. Simple stuff I can fool myself into believing that I almost understand, partly, but when we reach the giddy heights of prototypes and what-have-you, my knees fail me and I fall, prostrate, to the floor. One day I will understand; one day...


Meanwhile...


Have a nice day


Douglas
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Quexp wrote on Shaz's profile.
I absolutely love your profile/pic! :kaoluv:
Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
I made a battle results screen for my minigame.. any feedback? :)
Things I thought would never happen but just did: I needed to use my snow shovel. In August. In the Northern Hemisphere.
So I finished Cupcake, now I need to figure out my next project!
Do I pick up one of my incomplete games?
Do I start something entirely new???
The possibilities are endless!

Forum statistics

Threads
100,682
Messages
978,385
Members
132,308
Latest member
Amarina
Top