Hey, I was making a text-based simulation game and needed a way to track time, with about 6 AM being the start of "day" and 6 PM being the start of "night" for simplicity. (Ideally night would start at 8 PM, but a 12 hour difference would be easier)
Does anyone know of any scripts that may already exist in a library that would do that for me? If so, where should I find it? I'm not very experienced with Quest, or coding in general, so it would mean a lot to me to get some help. ^^
EDIT: I almost forgot. I'd like the in-game time to pass as the player moves and does different actions, not with real time.
EDIT 2: Thanks to user Io for helping!
I don't know about existing scripts/libraries, but here's how I would do it. Also, this got long while I was typing it, but I swear it's not as scary as it looks if you read it one step at a time!
Create an object called Clock, and (Optional) stick it in a debugroom never to be seen.
Give it attribute Minute as a double, and attribute Hour as a double.
When select your Minute attribute, and use that 'plus sign' button to give it a change script. Ie, "Whenever Clock.Minute changes, do THIS:"
Have the change script be, and pardon my psuedocode:
if Clock.Minute>59: Clock.Minute=Clock.Minute-60 Clock.Hour=Clock.Hour+1
This means, whenever Clock.Minute hits 60, it circles back to 0 and Hour advances by 1. This even handles cases like where you're at Minute 59, then advance 120 minutes to 179; reducing Clock.Minute by 60 calls the changescript again, reducing it by 60 over and over and increasing Hour over and over until you're back below 60.
Then, simply do something similar with Clock.Hour:
if Clock.Hour>23: Clock.Hour=Clock.Hour-24
This will handle a day passing.
That's the simplest form. Adding to this, if you want to manually track Day and Night, then add to clock the String Attribute DayNight and change Clock.Hour to something like this:
if Clock.Hour>23: Clock.Hour=Clock.Hour-24 else (aka we're at a possible hour, not hour 37 of the day): if (Clock.Hour>=6 and Clock.Hour<20): Clock.DayNight=Day (It's between 6AM and 8PM, so it's day) else: Clock.DayNight=Night(It's either before 6 or after 8, so it's night)
"But wait!" you say. "What if I want to display the actual time, like if I look at a stopwatch it prints out the time?"
Not a problem! In the code that prints out the time, instead of simply printing a line, have it run a script similar to this:
if Clock.Hour=0: (12AM case) if Clock.Minute>=10: print("The time is 12:"+Clock.Minute+" AM") else: print("The time is 12:0+"Clock.Minute+"AM") elif Clock.Hour<13: (AM hours) if Clock.Minute>=10: print("The time is "+Clock.Hour+":"+Clock.Minute+" AM") else: print("The time is "+Clock.Hour+":0+"Clock.Minute+"AM") else: (PM Hours) if Clock.Minute>=10: print("The time is "+(Clock.Hour-12)+":"+Clock.Minute+" AM") else: print("The time is "+(Clock.Hour-12)+":0+"Clock.Minute+"AM")
Hope this helps!
Pixie has a time-date system in his 'zombie apocalypse' and/or 'deeper' tutorial game/s, and/or in his quest github site or quest doc site documentation, and it's probably/likely built into the quest engine version too
time and date can be very complicated or relatively simple, and it's a bit more/extra work having to manage every individual action/event, in how much times passes when doing that event/action, as well as if you're also applying time passage with movement/traveling (and/or worse: if using different 'distances' as well), so up to you on how complex or simple a system you want
using the modulus operator/operation makes the equation a bit more simple:
modulus operation: division but it gets/returns/finds the REMAINDER
modulus operator/symbol: %
clock_object.clock_time_seconds = clock_object.seconds_count % 60
// clock_object.clock_time_seconds = [0 to 59]
clock_object.clock_time_minutes = clock_object.minutes_count % 60
// clock_object.clock_time_minutes = [0 to 59]
clock_object.clock_time_military_hour = clock_object.hours_count % 24
// clock_object.clock_time_military_hour = [0 to 23]
clock_object.clock_time_civilian_hour = clock_object.hours_count % 12
// clock_object.clock_time_civilian_hour = [0 to 11]
// too lazy to do the format coding to handle whether to put a '0' in front, for proper stop-watch/time displayment
clock_object.military_time_display_string = clock_object.clock_time_military_hour + ":" + clock_object.clock_time_minutes + ":" + clock_object.clock_time_seconds
clock_object.civilian_time_display_string = clock_object.clock_time_civilian_hour + ":" + clock_object.clock_time_minutes + ":" + clock_object.clock_time_seconds
for the quantity/count/tally/amount/number of days/minutes/seconds, you'd just use normal division as usual:
quantity_of_seconds = VALUE / 60
quantity_of_minutes = VALUE / 60
quantity_of_days = VALUE / 24
civilian time (and its hours: dawn/sunrise, morning, noon/midday, afternoon, evening/dusk, twilight, night, midnight) (and day/night) (and am/pm), obviously takes a bit more coding to handle it properly (12:00 ---> noon/midday or midnight? am or pm? day/daytime or night/nighttime?, etc etc etc)
Also, I forgot to add!
A way to progress time whenever going to new rooms.
Create a new Function, and call it something like 'AddTime'. Functions are basically just code you expect to use a lot, so rather than rewrite it all constantly, you write it in one place and then just keep saying "Use the AddTime code" over and over.
Under AddTime, add a single parameter called TimeProgress. Parameters are basically a slot you can fill in the code; the function will use the name for that as a variable, and ONLY inside that function.
Once you have that, have the AddTime code itself be something simple, like:
And then, in every room where you WANT time to pass when the player enters, under the before/after/ entering room, add a simple:
This will cause AddTime's code to execute, treating its internal TimeProgress variable as the number 1. Or 5, if you want. Or 1353, whatever.
I made it sound more complicated than it is, but try it out!
The Pixie also has a library for Date/Time
Really useful, it can track the time of day, month, year. It can also trigger events or actions to be carried out at a specific time.
For all of Pixies other libraries and other useful information see below: