Tutorial: Day and Night System: Introduction and the Clock
Difficulty: Beginner
RPG Maker: 2000/2003
Author: Nickyout

So you wanna have a day/night system? A good one? Like, people will say "wow, (s)he's got a day/night system right there.". But you don't know how, and you don't really understand all that rm2k3 coding yet, but are willing to learn? This could be the tutorial you're looking for.


Introduction

This is a 4-part tutorial to creating a day/night system in rm2k(3). In the first part, we will create an internal Clock (time). In the second part, a Day and Night transistion. In the third, a Watch item. Finally, if you can't get enough, the fourth part is to create a system that allows you to give NPCs in your towns a day and night rythm, letting them walk back home in the evening, and back to their NPC spot in the morning.


1. Clock (time)
2. Day and Night system
3. A Watch item
4. NPC 'homegetter' (day and night rythm)

The steps have been built upon each other. In this tutorial series I assume that when you attend to step 2, you've already done step 1. I strongly suggest you follow the steps in the correct order. On the other hand, every step rounds up a complete feature, so you can stop at any step you want. If you only want a clock, you can stop at step 1. If you only want a plain day/night system, you can stop at step 2. Also, the tutorial series is written assuming you start as a beginner, but it gradually paces up as you progress.

In these 4 steps, there are parts called extra steps. I called them extra steps, because they're not necessary, but -you guessed it- extra. However, some extra steps must be done to do other extra steps on that subject later on.

Well, see how far you can go. Step 4 may be long, but I think it's definitely worth the time.




The most important part of a day and night system is the time system, the clock. A common event that ticks time away. Faster than in real life, otherwise you'll be waiting for nightfall forever.


Step 1: The Clock
Coding level [*----]
Open the Database window and go to Common Event. Make a new parallel process called CLOCK. Mark 'Appearance Condition Switch' on. Get a new switch called CLOCK and select it as the Condition Switch.

Insert the command 'Wait...' and input 10 x0.1 sec, so the parallel process will be run every second. Get a new variable called MINUTES. Add the command 'Change variable', choose MINUTES, choose add (+) and in set, set a number that should be added every second. Now add the command Fork 'Conditions' (aka Branch), select the variable MINUTES, then input for Set 60 and as in the drop down menu choose for above (more than, including). In the new Fork, do a change variable to MINUTES by subtracting (-) it by the set value of 60. Now do another change variable, and get a new variable called HOURS. In the Fork, add (+) 1 to HOURS.

If done correctly, every time the value MINUTES exceeds 60, 60 MINUTES will be changed into one HOURS.

Now we also want this to happen when 24 hours have passed, and another day has to pass. So within the Fork, after the two variable commands, add another Fork: choose HOURS this time, set on 24 and yet again choose for above. In the new Fork, subtract 24 from HOURS. Get another new variable, called DAY. Add 1 to the variable DAY.

daynight1

You now have a simple time system. If you don't want months and years, skip the extra step.


EXTRA STEP: Add months and years
Coding level [***--]

This extra step is to add months. Some months will have 31 days, some 30 days, and february even 28 or 29 depending on the year. This step will include these anomalies.

Since February is such a weird month, let's start with that one. Create a new Fork inside the HOURS Fork, below the two variable commands. Use for the fork a new variable, MONTH, and set the fork on 2, same (aka same as 2). Also, mark 'Add else case' on. If you want, you can add a Note in the Fork that says 'February', so you can easily find it back later.

Now the fun starts. Create a new variable, YEAR. Create another variable, [c]Year Checker (the c of CLOCK, as a reminder that this variable is used by the CLOCK event). Change variable [c]Year Checker, set this variable's value to the variable YEAR. Now change variable [c]Year Checker, mod by the set value of 4.

NOTE: Mod divides the variable with the set value, and instead of the outcome, he places the rest value back in the variable. So if you mod 7 by 4 you get 3. If you mod 25 by 5 you get 0. If you mod 127 by 10 you get 7, if you mod 127 by 100 you get 27. Like that.

Set a new Fork right after the 'mod': Fork [c]Year Checker, same as 0, and mark 'add Else Case' on. This basically means: if the year can be divided by 4 do this, else do that. Indeed, a leap-year. In this Fork, insert another Fork: Fork DAY above 30. Yes, this is different from minutes and hours, for there is a day 29 and no day 0. Insert in this new fork a change variable: Change DAY, subtract 29. Add another change variable: Change MONTH, add 1. Now go to the Else Case of Fork '[c]Year Checker, same as 0'. Copy the Fork 'DAY, above 30' into this else case, and change the 30 in the fork to 29, and the 29 in the change variable to 28. That was february.

daynight2

Now we're gonna do the rest of the months. Recall that from January to July, the amount of days in a month go 31-30-31 (excluding February) and then in August, right after July, they go 31-30-31 again until December. Like 31-2?-31-30-31-30-31 31-30-31-30-31. During the first 7 months, odd numbers get 31 days and even numbers 30. During the last 5 months, even numbers get 31 days and odd numbers 31. Hmm...

In the Else Case of the Fork 'MONTH, same as 2', insert another change variable command. Get a new variable, [c]Month Checker. You might've guessed it, we're gonna do the same trick as with the leap-year. Change [c]Month Checker to the same value as MONTH. Now Mod [c]Month Checker by 2. Odd number will return a 1, even numbers a 0. Make a new Fork: Fork MONTH, below 7 (that includes 7), add else case. In this Fork, make another new Fork: Fork [c]Month Checker, same as 1, add Else Case. In this fork, copy the DAY Fork you already made in February, but now change the Fork to 32 and the Change DAY subtraction to 31. In the Else Case of the Fork [c]Month Checker, Copy this DAY Fork again, but now change the Fork to 31 and the Change DAY subtraction to 30. Good, we're almost there. Now copy the whole Fork [c]Month Checker, and copy it into the Else Case of the MONTH Fork. Then swap the two DAY Forks; Fork Month Checker same as 1 should get DAY Fork 31, the Else Case should get DAY Fork 32.

daynight3

Now all we miss is that every 12 monts make a year. Remember, the 12th month exists as well, so a new year should be added when the 13th month starts.

Add a new Fork, right under (not in!) the Fork 'MONTH same as 2' This Fork should be: Fork MONTH, above 13. No Else Case. Inside this Fork, Change MONTH by subtracting 12, and Change YEAR by adding 1.

daynight4

That's it. You now have a clock with time and date.

END OF EXTRA STEP


In game, when you set the switch CLOCK to ON, your clock should start ticking. But that is all. There's no night and day yet; the maps don't turn dark when night falls. In the next part we will create a Day and Night system.

Day and Night System: Introduction and the Clock
Day and Night System: Time of Day - Tint Settings
Day and Night System: Making a Watch Item
Day and Night System: NPC Homegetter



Click to Return to the Tutorials Page