Tutorials :: Complete Day and Night system - Step 1: Intro & The Clock :: Ultima Island: A friendly online community focusing on game development. Games, Tutorials, Resources, Articles, and much much more...

Welcome Guest [Submit Content] [Log In][Register]
Working on a game project? Why not sign up and start your own upcoming project site for free!
Tutorials :: Complete Day and Night system - Step 1: Intro & The Clock
Complete Day and Night system - Step 1: Intro & The Clock
16 Comments, 1490 Views
 rating: (14 votes)
Complete Day and Night system - Step 1: Intro & The Clock

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.



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


Quote:
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.



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.



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.



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.
submitted by LOLninja
You are not permitted to rate tutorials...
 
Latest Comments
LOLninja (Offline)
plus 4 exp plus 4 gold lol!
stephenc644 (Offline)
At least we are not making this like "Castlevania 2: Simon's Quest". When day becomes night in it, it stops the game, brings up a box and says "what a horrible night for a curse!" then changes to nightime.

P.s. i am not the Angry Video Game Nerd, just a fan of his.
Yoshi-TRM (Offline)
I'm currently working on a comprehensive(somewhat) weather system to go along with your day and night system, we'll see if I can make a tut out of it.
LOLninja (Offline)
I've got this whole system in a project. PM me if you want to use it for your weather system.
gamemaker111 (Offline)
I don't get it im a noob!!! I don't know how to use forks!
gamemaker111 (Offline)
Hey i got gold when i posted my comment. O hey Nickyout i saw you in the ui1 game your the lol ninja lol.
Aten (Offline)
The only really really good D&N system I saw was in Radiata Stories. That was awesome.
Amonitas (Offline)
Full five!
If you don't understand it, you just check the scripts and you do, if not, you are a noob!
yoyomonkey (Offline)
I'll have to try that!
Animemaster984 (Offline)
Nice first part !
Quick User Panel
Username:

Password:

Welcome Guest, please login or register

Change Style:
Shout Box
Gretgor says:
You did it wrong, man. Anyways, you turned a frog into a screwdriver.
dragoniqbal says:
LOLZ! I tried.. Ayy Gretgor, i can turn a frog into a
Gretgor says:
MAY A NEW WORLD OF GAMING BE BORN FROM THE ASHES OF... UHHH.... Someone finish this sentence for me, thanks.
Lemon_EX says:
Sorry, wrong web site.
Gretgor says:
Well, fix that, then.
Miscellaneous

Donate

RSS Feed

Play-Asia.com - Buy Video Games for Consoles and PC - From Japan, Korea and other Regions!