MV Using Update to wait for x number of frames

Forgive me if this questions has been asked elsewhere, but I haven't been able to find a good example I've been able to make use of.

So I'm continuing to try to get into code base and still having some difficulty wrapping my head around the language. I'm trying to build a little piece of code to open a text window which displays a message, hangs around for a few seconds and then closes itself. Something very similar to Galv's Time Message Pop Ups. After some struggle, I've built a window that displays my text, but getting it to wait is giving me trouble.

From what I've inferred from other threads, it sounds like the practice is to use the window's update method to have the object update some number of times or frames and then close. However, I don't seem to understand how to put this into practice. I've tried using a for loop in different ways (Having it take place in the update method as a countdown, as well as using a loop in the initialize which calls the update method every time), but the end result is that nothing seems to delay the next step where the window closes.

Am I on the right track, or way off here? Would someone happen to know a relatively straight forward example somewhere in the code base or in a plugin that I might use for guidance? Any help would be appreciated.

Thanks!
Graphics._framecount is one way, it increments every frame. You can capture it at the beginning of a process, and then check it each frame until it reaches the original captured number + your amount of waiting frames.

e.g. someObject.targetFrame = Graphics.frameCount + 60, then check in the update method for Graphics.frameCount to equal that amount

Another version is the tick method. Simply have a variable or property global to the update method, and either start at the wait time (e.g. someObject.tick = 60) and decrement every frame until it reaches 0, or start at zero and increment every frame until you reach your desired time.

If you run a for loop in the update method, it's going to finish that loop on the same frame it starts.
@standardplayer
Thank you for your guidance. I spent a little time trying these solutions out and haven't gotten it to work yet. I think I'll need to start fresh in the morning, but I did want to say thanks for taking the time to respond! I'll let you know how it turns out.
I'm happy to help. I'll tell you what, I'll go ahead and make a little tutorial here.
So the first step, which I'm sure you've already done, is to alias the update function.
Next would be to figure out which timing method you'll use. I've decided for this example to use the tick countdown method.

Let's assume we're using the Map Scene.

JavaScript:
//Create a sample variable for the sake of this demonstration
let tick = 60;

//Declare a function to run when the timing requirement is satisfied. When tick reaches 0.
function onComplete(){
    console.log('the timer has reached 0')
}

//Declare and assign alias
let sp_alias_SceneMapUpdate = Scene_Map.prototype.update;

//Write the new update function, and call the original

Scene_Map.prototype.update = function(){
    sp_alias_SceneMapUpdate.call(this) //This will run the original update function
    //everything below is the code to 'add'
    if(!tick){ //this will be true when tick reaches 0. It's like saying if(tick == 0)
        return     onComplete()
    }
    --tick //decrement tick by 1. This is like saying tick -= 1; This will only run until tick
           //reaches 0. Once it does, the return call above will abort this part of the update process
}


So here, the update function will run the same code it did before you aliased it, but once that completes, it will run the code below the alias call. If the tick variable is greater than 0, it will decrement the value by 1, and move on. Once it reaches 0, it will run the onComplete function, and then never reach the decrement portion again until tick is reassigned a value greater than 0
@standardplayer

Thank you so much! You certainly didn't need to provide an example, but you are a hero for doing so! Thanks to your code above I was able to get this to work. It looks like my failing was getting the tick variable assigned at the right scope level and then accessing it correctly from the update function (Javascript requires the .this keyword a lot more frequently than I'm used to and it's been a real challenge to make it stick with me). But now I've got working just like I had wanted it.

Thank you again for taking the time, you're awesome!

Original thread: https://forums.rpgmakerweb.com/threads/using-update-to-wait-for-x-number-of-frames.126362/