Tracking Time in Common Events

in Tutorials

Yo. Uncle Despain here, with my newest RPG Maker VX Ace tutorial. Last time around, we made a bank where the player is able to store and withdraw gold. A lot of people have been asking about adding interest, so today’s tutorial will explain a way to do that. And more!

What we’re going to learn today is how to track time in common events. It’s easier than you might imagine—in fact, it’s super simple. The important thing about the idea is what to do with it.

When you can track the passage of time, you can add a tremendous amount of interesting mechanics to your game. I mentioned interest for your bank. You can expand the same idea for all sorts of other things—growing plants for a farm/planting system, items that level up as time passes. A day/night system, or weather, or seasons. All of these mechanics are possible with a simple common event that allows the game to keep track of time.

So let’s take a look. This is the most basic way to accomplish the idea.

(click for full view)

Ridiculously easy, right? As simple as this event is, let’s take a moment to look at what it does.

You understand how common events work—we went over those in a previous tutorial. So we know that this event will continually run in the background while the player is exploring your game world.

Every ten seconds, this event increases a variable. In this example, the variable is called “Hours”, but it can be anything you want. Don’t feel the need to measure time in longer “hours”—even if that’s what you name your variable, the player doesn’t see it. We’re just tracking time, and I smaller increments allows for more accurate tracking. You’ll see that, in this example, we wait ten seconds before an “hour” passes.

Of course, that amount of time can be changed—you might want to wait a minute, or more. All you’ve got to do is add more wait commands. Remember that one frame is one sixtieth of a second, so a sixty-frame wait will be about one second.

This is the only most basic way of tracking time. You might want to add a little more depth to the idea, so let’s consider tracking minutes and hours together.

This version uses two variables. If you understand conditional branches, it’s pretty straightforward. Every sixty frames (every second), the event goes into a conditional branch. If sixty minutes have passed, it adds to the hour variable and resets the minute counter. If not, it adds a minute. In this version, a “minute” passes every second, and an hour passes every sixty seconds. You might want to change that for your game—it’s just a matter of changing the number in the conditional branch, or changing the wait commands.

That’s all it takes to track time in your game. The parallel process common event will continually loop in the background of your game. Remember that you can turn it off with its Condition Switch, so you can make sure that time doesn’t pass when your player is in a cutscene. Just remember to turn it back on afterwards.

“Sure, that’s cool”, you say. “But what do I do with it?”

In my next tutorial, we’ll dive a little deeper. We’ll make a simple day/night system, and we’ll add interest to our bank account every day that passes. Stay tuned. And happy game making. 🙂

About the author: Jason “despain” Perry has been using RPG Maker for over a decade, and in that time his articles, tutorials, and graphical resources have helped countless RPG Maker users on community forums. He currently runs the website, where he co-hosts an RPG Maker podcast and regularly posts new articles and tutorials.

Comments on this entry are closed.

  • light487

    Just curious why you used all those separate wait commands (10 x 60 frame) instead of just using a single wait command for 600 frames? I know it was just an example.. but yeh.. curious why you did it like that? Is there some secret where using multiple waits saves memory/cpu cycles or something?

    • Despain

      For organization. If we know that 60 frames makes one second, each of these wait commands is one second. It makes it easier at a glance.

      Also—and I’m not 100% certain of this one, because it may have changed since older versions of the program—but this way the commands will be easily broken up if something interrupts them—say if another event runs or the player goes into the menu. Say that you use one wait command for 600 frames, and during that command, the common event is interrupted. When it resumes, it would start the wait command over.

      • light487

        Ok yeh.. if it does do that latter thing, I could understand that thinking.

  • Devin Watson

    Is it cheating if I took a scripting shortcut on this to compute interest (using this with the previous Creating a Bank tutorial)?

    Basically I expanded it to catch when midnight rolled over (hours = 0), then inside the conditional branch I evaluated a script snippet: $game_variables[3] += ($game_variables[3] * 0.02).truncate

    Where 3 is the variable ID of “Gold In Bank” in my project. It works quite well, and adds in 2% interest on the gold in the bank account every 24 “hours” of game time. The truncate prevented Ruby from converting the variable into a float, which does mean some loss of precision, but I was willing to let it go.

  • Chris

    Thank you so much dude. Might not be the place for it, but I clicked your banking link and now I have a bank as well as soon a Day and Night system. You rock so much. Thanks again.