RMMV Interpreter's wait method within custom function

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,249
Reaction score
726
First Language
Poland
Primarily Uses
RMMV
To the point...

I want to know how to properly tell interpreter to wait for another method within function?
Example:
JavaScript:
var delay = 120; //2 seconds
$gameMessage.add(message1);
$gameMap._interpreter.setWaitMode('message');
$gameMap._interpreter.wait(delay);
// Basicly at this point game should (must) wait 2 seconds (120 frames) for next message AFTER user's input (Action key)
$gameMessage.add('message2');
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
First Language
English
Primarily Uses
RMMZ
@Soulrender

Very good question. I really hope to see responses from the folks experienced with the architecture on either the solution or the next best workaround.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,942
Reaction score
8,614
First Language
German
Primarily Uses
RMMV
unfortunately wait doesn't function in the way its name suggests, which is what makes this idea complicated.
I can't give you the code, but I can explain to you what really happens inside the engine.


There is a main game loop that contains a lot of objects like the events and display update functions and more. This loop is processed once per frame.
the "wait" command now basically tells that loop "skip this object for x frames".

In the case of an action button event, that looks like a wait.
In the case of a parallel process, this skipping results in less processing and less lag.

The problem begins if you want to have the "wait" based on a different object in the game loop instead of its own processing, because that would require global access instead of instanced access, or some difficult handshake or something like that.
And that is something where I only know the general theory but not the exact implementation of RM's game loop, so I can't help.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,849
Reaction score
2,187
First Language
EN
Primarily Uses
RMMZ
I'll paste this here for others:
The effect of this:
JavaScript:
$gameMessage.add("text1");
this.setWaitMode("message");
this.wait(120);
$gameMessage.add("text2");
this.setWaitMode("message");
...is to add 2 lines of text to the message, set the interpreter's wait mode to "message" (twice, 2nd time does nothing), then start waiting for 120 frames while the message is showing. Instead it should be 3 script calls, one after the other:
JavaScript:
$gameMessage.add("text1");
this.setWaitMode("message");
JavaScript:
this.wait(120);
JavaScript:
$gameMessage.add("text2");
this.setWaitMode("message");
This gives the interpreter appropriate opportunities to check its wait mode and/or wait time.

For your situation, you may be better off inserting commands into the interpreter instead. This sort of thing can be used in a Script command to insert commands into the current interpreter:
JavaScript:
var i = this._indent;
var pre = this._list.slice(0, this._index + 1);
var post = this._list.slice(this._index + 1);
this._list = pre.concat([
 { code: 101, indent: i, parameters: ["Actor1",0,0,0] },
 { code: 401, indent: i, parameters: ["text1"] },
 { code: 230, indent: i, parameters: [120] },
 { code: 101, indent: i, parameters: ["Actor2",1,0,0] },
 { code: 401, indent: i, parameters: ["text2"] }
], post);   // new array, do not edit original
Code 101 is Show Text (faceset name, faceset index, background, position), 401 is Show Text (actual text), and 230 is Wait.
:kaophew:
This is the approach I'd use, but I imagine there are alternatives.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,249
Reaction score
726
First Language
Poland
Primarily Uses
RMMV
@caethyril - this code works well and that's a very good starting point for solving totally my main problem with MV, however it has one flaw, "Script..." event is limited to 12 lines, but... I'll check something you mentioned somewhere else.

Edit:\\ Huh o_O. Strangely enough... It's working, but... um... Naah, nevermind, it's working, so I won't will dig it further. However, I'm keen to see other options.
 
Last edited:

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
4,509
Reaction score
1,730
First Language
Dutch
Primarily Uses
RMMV
@Soulrender even if scriptcall is max 11-12 lines, you can set all it behind each other,
while the lenght is limited so far I know. so you get basicly 1-3 lines in total.
example is

if (12345678913dksnklgnsadkgnlsnglnsalnghlsfnhkgnsfklhnkldfnhnadlnkadk)
else
dmsdkgklsgksfkgskghkfkhjkdlhklsndkl;hn;lasdnhl;nasdhlnhikn etc etc (with actual code)

so you scriptcall has 2 lines, but you can save the code on a txt file for easier edit,
and paste if needed :)

so you never use the full 12 lines this way, short codes are easier to read, very long codes,
can be copy paste, because I use a 50 liner in a scriptcall to 3 lines
(if true, do this
esle
do what if it's false
but paste the code after each other if the code is longer than 12 lines ^^
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,249
Reaction score
726
First Language
Poland
Primarily Uses
RMMV
@ShadowDragon, yeah, but I already tested what @caethyril suggested i his post as a method in a custom class in ES6 standard. Only one thing doesn't go off my mind:
$myClass.testRun() wouldn't run at all with script call, but $myClass.testRun.call(this) executes @caethyril's code without a scratch.

Edit: It looks like there is no other way than translating classic script calls to number codes for interpreter. Great.
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,849
Reaction score
2,187
First Language
EN
Primarily Uses
RMMZ
$myClass.testRun() wouldn't run at all with script call, but $myClass.testRun.call(this) executes @caethyril's code without a scratch.
That is because of scope/context. The this keyword references the current context: in a Script command, that is the current Game_Interpreter. The example I gave assumes that this points to the relevant interpreter, i.e. it assumes that it will run in a Game_Interpreter context. The call method invokes a function with a specific context, i.e.
  • $myClass.testRun() will use a this value of $myClass.
  • $myClass.testRun.call(this) will run the function in the current context.
You might have seen apply and/or bind before: these are similar to call, they are used to change the context in which a function runs.

Relevant articles:

Edit: It looks like there is no other way than translating classic script calls to number codes for interpreter.
If implementing this as a plugin, you could write your input data in a "nice" format, then have a function translate that into event commands. Regardless, you might find the Event Code sheet here helpful:
It's for MZ but I think the command codes/parameters are mostly the same for MV~
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
First Language
English
Primarily Uses
RMMZ
@caethyril your post with the interpreter commands and their human alternatives turned out to be a lifesaver. It answered a question I didn't even know I was going to have :)
 

Latest Threads

Latest Posts

Latest Profile Posts

The new Dune movie reminds me of the game Dune 2 made by Westwood. A quality product on its own, but extremely disloyal to its source of inspiration.
Terrible Writing Advice, you've done it again.
1635026211997.png
Feeling like my new profile picture is nice. Thinking of making it semi-permanent, does any one has an opinion? Does it look too evil or does it work as a public profile picture? :)
Bishiba.png
My washing machine is a supernatural being. I lost a piece of clothing in there a month ago; searched up and down, inside other clothes, nothing. It just vanished.
Today, put in a new load. When I pull it out, the missing clothing is back! And a sock was sacrificed in the process :yswt2:

Forum statistics

Threads
116,031
Messages
1,095,108
Members
151,362
Latest member
Haniel_Sword
Top