how to pause (temporary) script execution

hey all, its been a while right?  Well i have a new question, n i'm short on time so i'll just be frank..... or jim. lol 


well here it is : how do i use wait in scripting? see i plan to make tutorials on how to make certain systems for rmmv, but im in the dev stage currently and this issue is really bugging me so any help will be appreciated.


~domo~
Let's say you use a window as an example; you could program a counter into the update method of the window.


Then, you only execute the code if the wait count is at 0; Window_Message in the engine has a similar method called startWait.


For some reason the zeros are not showing on my screen in the code snippet, but the empty spaces are to check for 0.


Example:

Code:
Window_Base.prototype.initialze = function() {
  this.wait = 0 ; //Initialize wait to 0
};

Window_Base.prototype.update = function() {
  this.updateWait();
  //Only executes when wait is 0
  if(this.wait === 0 )
    this.drawStuff();
};

Window_Base.prototype.setWait = function(value) {
  this.wait = value;
};

Window_Base.prototype.updateWait = function() {
  if(this.wait > 0 )
    this.wait--;
};

Window_Base.prototype.drawStuff = function(text) {
  this.drawTextEx(text,0 ,0);
  this.setWait(120);
  //Sets wait to be 120 or  120 frames / 60 fps = 2 seconds
};
Thankx for the quick reply, but sadly i already tried that and it didn't work. i even tried making a counter directly in the update method, but when the condition was met i got nothing.... tried a console.log but still nothing. which is why i was wondering if there was a pre-made method/function i could use instead. Any ideas?   
Could you provide some of the code so I could see it? It might help me come up with some ideas.
I have one other idea, which I used recently. 

You could call the JavaScript Date.now() method, which will return the current time in milliseconds and have a startTime, and elapsedTime properties.
In update you would update the elapsedTime every frame, then check the difference in time before executing the function you want.

Code:
Window_Base.prototype.initialize = function() {
  this.startTime = ;
  this.elapsedTime = ;
}
Window_Base.prototype.update = function() {
  this.updateElapsedTime();
  if(this.checkTimeDifference(5)) {
    //5 second interval
    this.drawText('text', , , 100)
    this.resetStartTime();
  }
};

Window_Base.prototype.updateElapsedTime() {
  this.elapsedTime = (Date.now() / 1000 ); //Returns the time in seconds
};

Window_Base.prototype.resetStartTime() {
  this.startTime = (Date.now() / 1000 );
};

Window_base.prototype.checkTimeDifference = function(value){
  if( Math.ceil(this.elapsedTime - this.startTime) > value)
    return true;
  else 
    return false;
};
//-----------------------------------------------------------------------------
// BattleScene_ivb ++ v.1
//-----------------------------------------------------------------------------
// The scene class of the map screen.

var sceneMap_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
sceneMap_update.call(this);

var battle_mode = false;
var isbattleStarting = false;

if(Input.isPressed('shift'))
{
battle_mode = true;
}


if(battle_mode == true)
{
isbattleStarting = true;
console.log("this area is now a battle scene");
}

if(isbattleStarting == true)
{
this.startBattleEfx();
$gameScreen.startShake(3,7,60);
// fade out screen
//show battle start message
//wait -- - -- - -- - -- -- -- -- - ----- --- - -i need to kinda pause here
//fade in screen
//$gameTemp.reserveCommonEvent(2);
}

Scene_Base.prototype.update.call(this);
};


see my problem?


without the (Wait) no one can see the message because it goes by too fast.
The date wait might be able to help you then in the above post; I used it in another plugin of mine to do sliding animations after a 5 second interval.
Also, your Scene_Map.prototype.update.call(this); Calls all the Scene_Base.prototype.update code also.
The date wait....? i don't understand. 
So, in JavaScript there is a Date class that you can call.
Date.now() returns the current time in milliseconds; to get seconds, we'd have to divide Date.now() by 1000 (Date.now / 1000).
 


Now, let's say you wanted to check when 5 seconds go by from when you initially called it.
You would have one Date.now() in Scene_Map.prototype.update; this would keep updating the time for you.
Then you'd have another one Date.now(), that you only update after 5 seconds has passed to reset the difference between the two times.

Code:
//-----------------------------------------------------------------------------
// BattleScene_ivb ++ v.1
//-----------------------------------------------------------------------------
// The scene class of the map screen.

var sceneMap_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
    sceneMap_update.call(this);
    this.updateElapsedTime(); //Repeatedly updates the time
    var battle_mode = false;
    var isbattleStarting = false;

    if(Input.isPressed('shift'))
        {
          battle_mode = true;
        }


    if(battle_mode == true)
    {
        isbattleStarting = true;
        console.log("this area is now a battle scene");
    }

    if(isbattleStarting == true)
    { 
      this.startBattleEfx();
       $gameScreen.startShake(3,7,60); 
      // fade out screen
      //show battle start message
      //wait -- - -- - -- - -- -- -- -- - ----- --- - -i need to kinda pause here
      //Checks if 5 seconds has passed
      if(this.checkTimeDifference()) {
        // run whatever is here when 5 seconds passed 
        //We can add other conditions to this if statement to prevent it from being repeated
        this.resetStartTime(); //resets the time, so we can wait another 5 second interval to run our code
      } 
      //fade in screen
      //$gameTemp.reserveCommonEvent(2);
    }

    Scene_Base.prototype.update.call(this);
};

Scene_Map.prototype.updateElapsedTime = function() {
  //Date.now() is a JavaScript method that returns the time in milliseconds from 1970, so this is real time
  this.elapsedTime = (Date.now() / 1000); // Updates the time when called
};

Scene_Map.prototype.resetStartTime = function() {
  this.startTime = (Date.now() / 1000); //resets the start time, so the difference between elapsed and start isn't 5 seconds for example
};

Scene_Map.prototype.checkTimeDifference = function() {
  if( (this.elapsedTime - this.startTime) > 5 ) //Checks if elapsed time is 5 seconds away from our start time
     return true
    else
     return false
 };
Thankx this is just what i needed. You're a lifesaver. 🙂  
Glad I could help; if you have any issues with the solution, feel free to contact me.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-pause-temporary-script-execution.59475/