SMILE GAME BUILDER

SMILE GAME BUILDER

Not enough ratings
Working Time and Date System (updated for v1.11)
By JKPubs
A tutorial for creating a fully working time and date system within Smile Game Builder. This system updates the time live on screen and transfers between maps. Once you have this set up, many options become available to the user such as real day and night cycles, time specific events, farming, resource respawn, crafting that takes a set amount of time, etc.
2
   
Award
Favorite
Favorited
Unfavorite
Working Time System (Updated for v1.11)
This is a major overhaul of my Time System which now a Time and Date System with each month consisting of the proper amount of days. And thanks to the addition of string variables, we can use those to store the names of months and days of the week for use in various things. The size is reduced by 35-40% over my previous version and uses only 13 images instead of over 60 like before.

This is how it is done:
Download the images used in this tutorial and import them:
https://www.dropbox.com/s/guwatzu9kwes6as/

Alternatively, you can download the project file which has some basic practical uses on the map. Then you can investigate the events yourself.
Project File: https://www.dropbox.com/s/amgvs2eg34vzkjp/

Start by creating 2 new Common Events. We'll name them "Time" and "Date".

Go into the Time common event and set it to Automatically Start.

Now add a wait panel. What you set this to will determine how long you want a minute to last. For testing purposes I usually set this to be a 0.1 second wait. But for practical use, you may want to set this to be somewhere in the range of 2.5 seconds which would make 1 game day last 1 real time hour.

Now you Use a variable box panel to add 1 to a variable which I named "time_min" this just increases the minute.

Next we're going to add a variable box check for time_min. Check if it is greater or equal to 60. We need to make sure the minutes wrap around to zero.

In the "Yes" section for that:
-Assign time_min to zero
-Add 1 to a new variable "time_hour"
-Check Variable box time_hour is greater or equal to 24
-In the "Yes" for that:
--Assign time_hour to zero
--Execute common event "Date" with wait. (we'll set this up later)
--End Branching
-End Branching

Now below all that, Check if time_hour is greater or equal to 12
In the "Yes" for that use "Change String Variable" named "ampm"
Set this to "pm"
In the "No" section, do the same thing except set "ampm" to "am"
This will be used for the am/pm HUD and also for messages.
End Branching

Advanced Variable Box:
-To What: Local Variable 0
-How: Variable Box time_hour
Do what: Assign

Check "Local Variable 0" is greater or equal to 12
In "Yes" Variable box subtract 12 from Local Variable 0
End Branching

Now we're going to display the images.

Start by using Display Image to show the colon image. If you're using my images you can use my coordinates as well.
Set this to show at X:48 and use "image display number" 2.

Check string variable "ampm" is the same as "am".
In "Yes" "image display number" 5 to show the AM image at X:108
In "No" "image display number" 5 to show the PM image at X:108
End Branching

There will now be a series of checks inside of checks.

Check "Local Variable 0" = 0
Yes:
-Image display 0 at X:0 and the "1" image
-Image display 1 at X:24 and the "2" image
No:
-Check "Local Variable 0" = 1
-Yes:
--Hide displayed image 0
--Image display 1 at X:24 and the "1" image
-No:
--Check "Local Variable 0" = 2
--Yes:
---Hide displayed image 0
---Image display 1 at X:24 and the "2" image
-No: ....

Continue this until you hit 10 and 11 and instead of hiding displayed image 0, display it showing a the "1" and image 1 show the zero and 1 images respectively.

Then there's a flood of "End branching".
Below all of that, we move onto displaying the minutes.

Advanced Variable Box:
-To What: Local Variable 1
-How: Variable Box time_min
-Do what: Assign

Advanced Variable Box:
-To What: Local Variable 1
-How: Fixed Value of 10
-Do what: Division

Now we do the tens for the minute display.

Check Local Variable 1 = 0
In Yes: image display 4 to show the zero image at X:60
In No: Check Local Variable 1 = 1
....
Continue ending with showing image 5.

After the last End Branching...

Advanced Variable Box:
-To What: Local Variable 1
-How: Variable Box time_min
-Do what: Assign

Advanced Variable Box:
-To What: Local Variable 1
-How: Fixed Value of 10
-Do what: Substitute Divided Remainder

Now we display the ones for the minutes.

Check Local Variable 1 = 0
In Yes: image display 3 to show the zero image at X:84
In No: Check Local Variable 1 = 1
....
Continue ending with showing image 9.

And thats the end of the time event.
As an added feature, you can set the event sheet condition to check if a switch called "time_stop" is off. This will let you start and stop time by flipping that switch in your events.

Now we move on to creating that "Date" common event.

Set this one to be "No Trigger (execute from another event)" as we only need this to be triggered when the clock wraps around at midnight.

Add 1 to variable time_day
Add 1 to variable time_week
Add 1 to new variable time_total
time_total is only for if you want to do things over time. This allows you to do things like farming, mining, chopping trees and having the resources "grow" back. You can see more on this in the project file.

Check new variable "time_week" = 1
In Yes: Change new String variable "Weekday" to be "Monday"
In No: Check new variable "time_week" = 2
...
Continue through the days of the week until you hit Sunday
Then for the "no" part of Sunday:
-Assign time_week = 1
-Change String variable "Weekday" to be "Monday"
This ensures that it always wraps around properly.

After the End Branches, we do another series of checks for the months to make sure they have the proper amount of days and wrap around accordingly.

Check new Variable time_month = 0
In Yes:
-Change new string variable "month" to be "January"
-Check time_day greater or equal to 31
-In Yes:
--Assign time_day = 0
--Add 1 to time_month
--Change string variable "month" to be "February"
-In No:
...
Repeat this process until you get to December making sure that each month has the proper amount of days.

For December you need to add one additional panel after you change the string variable back to January.
Add 1 to a new variable time_year

After all the End Branching...

That is the end of it! You're good to go!

Keep in mind you can now use \v[X] to show variable numbers and \s[X] to show string variables in dialogue and message windows.

This now opens up a world of possibilities for you! You can create an actual growing farm, chop down a tree and have it regrow over time, have NPCs do different things based on the time of day or the day of the week, crafting over time and so much more!
3 Comments
sylardean 27 Jun, 2021 @ 7:52am 
NICE!

Here's a problem I see with it.. it's not a true clock, it's more of a timer, cos when you talk to an event the timer pauses until you continue on. This however could be used for growing plants or doing timed events and such.

It's a shame really theres no built-in function on SGB that will allow display of time from your system you are running a game from, like from a PC, Playstation, Nintendo.. etc. I'd love to have something on my clocks that displays the REAL LIFE time.
saviorho 17 Mar, 2021 @ 2:00am 
Thank you very much.
Your code has saved me a lot of time
Lyendhal 5 Jul, 2018 @ 12:58am 
Hi, very good job you've done !!!

But, I've got a problem with it, the AM/PM image "flash" on the screen every passing minute and also the compass that i added.

Not really a problem, but a bit annoying. Do you know a way to correct this by any chance ?