RMMV Interpreter's wait method within custom function

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,243
Reaction score
718
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,879
Reaction score
8,587
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,828
Reaction score
2,164
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,243
Reaction score
718
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,493
Reaction score
1,723
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,243
Reaction score
718
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,828
Reaction score
2,164
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 Profile Posts

One uncomfortable truth that has withstood the test of time, is how most people will stand by while they see a crime happening, unless it's illegal to stand by. We probably wouldn't have stories about "special heroes" or games about heroes if the "everyday common folk" were largely capable of being heroes. Heroes face dangers that most people are not willing to.
I'm having toooo much fun designing the new MP (Mental Psyche) system. I've only worked it out for enemies so far, but it's fun to stun them, then go after their MP and delete them instead to farm for better item drops.
anyone know of a place I can promote my game? sorta like game awards but for indie devs, like a place where I can drop a trailer and like stir up some hype
Doing RPG Maker News for 17th October 2021

That moment when you came up with a very good game title, but when you searched it, it has already been used... T.T

Forum statistics

Threads
115,882
Messages
1,093,687
Members
151,125
Latest member
krawm
Top