Keeping In-Game Time

Weezil_Of_Mods
24 Jul 2013, 17:57
The game I am working on, you are essentially stuck at home for 24 hours. What I would like to do is create an in-game time system, where a minute goes by every 10 seconds. With a system like this, I'd like to be able to do time-related things, such as changing the ID of the video I have a television set to play every 30 in-game minutes (5 minutes), change the time on a clock when you look at it (of course), and end the game once the 24 in-game hours are up. I have a feeling that this can be done, and I've tried experimenting with timer scripts, but I can't seem to find any method that works.

Perhaps someone before me was able to pull this off, or would know how to? Any and all help would be appreciated.

Liam315
24 Jul 2013, 21:12
What you need is two separate elements. The first would be an object attribute that holds the value of the time. The second would be a timer with a script that changes the value of the attribute every x seconds. I would try something along the lines of the following:

Create a new object called master_clock or something similar.
Create 2 attributes on it, "hours", and "minutes." Make them both integers and set them to 0.
Create a timer called clock_control. Check "start timer when game begins," set the interval to 50 seconds, and enter the following script.
master_clock.minutes = master_clock.minutes + 5
if (master_clock.minutes = 60) {
master_clock.minutes = 0
master_clock.hours = master_clock.hours + 1
}

Now when you want to reference the time in your other scripts, you can refer to exact time periods when something happens. You can also add further if () { scripts to the timer to trigger certain things. e.g. A script using if (master_clock.hours=13 and master_clock.minutes<31) { would allow something to happen between the game times of 1pm-1.30pm.

This is a simplified version that updates the in game time in 5 minute chunks rather than 1 minute. It also assumes you'll be using 24 hour time starting at midnight. Changing this starting point to whatever time period suits your needs should be relatively easy, you'd just need another script or two to make sure it ticks over from 2359 to 0000. Using the master_clock object also allows you to add other attributes you might want to create and use like changing to a 12 hour clock with AM/PM, assigning qualitative descriptors like morning, afternoon, evening etc., or even adding something like changing weather at different times of the day.

Hope this helps, if you need further clarification of any points let me know.

Weezil_Of_Mods
24 Jul 2013, 22:46
I used the code you submitted, replacing master_clock with what I called it, obj_masterclock. The attributes are also where they are supposed to be, set as integers, and set as zero. The timer was made, going every 50 seconds.

For the current clock I wish to use for now, when you look at it, I printed the expression:

"The time is " + obj_masterclock.hours + ":" + obj_masterclock.minutes + ". In military time."

When I look at the clock, it says "The time is 0:0. In military time." When I wait the 50 seconds to signal the change, it still says this, the integer for minutes having not changed. Also, is there a method to print two digits for the integer (00:00) instead of just the one? For aesthetic purposes, not important.

Is there some mistake I may have made, or anything that could have an affect on it?

Liam315
24 Jul 2013, 23:30
Is the timer set to start when the game begins? If it is you might need to repost your game file to have a look at what's going on. You could also try enabling the timer by a script. This is probably stating the obvious but just to make sure I'm covering all possibilities, you'll need to type look at the clock a second time after 50 seconds to see the change, it won't reprint again automatically.

I forgot about displaying a 0. You'll need to program it to recognize single digits and add a prefix if necessary by adding two more attributes. These will be string attributes that you should set to the numeral 0 to begin with.

if (obj_masterclock.hours = 10) {
obj_masterclock.hoursprefix = null
}
else if (obj_masterclock.hours = 0) {
obj_masterclock.hoursprefix = "0"
}


Repeat and replace the hours with minutes, make sure this section comes after the part of the timer script where the actual hour/minute values are changed, not before. Take note of the quotation marks around the 0 in the prefix part of the script. This is because you're setting a string value, not an integer. Then alter your expression to read:

"The time is " + obj_masterclock.hoursprefix + obj_masterclock.hours + ":" + obj_masterclock.minutesprefix + obj_masterclock.minutes + ". In military time."

Weezil_Of_Mods
25 Jul 2013, 00:02
The timer does begin at the beginning of the game. But, if I have a script set to run before you enter the first room, click to continue, and THEN enter the first room, would that affect it? Otherwise I've followed these directions to a tee, save for speeding the time increments from every 50 seconds for 5 minutes, to 10 seconds for 1 minute.

EDIT: What I changed is there is now a timer that begins once you officially enter the room, which counts down, THEN triggers the clockcontrol timer, and then shuts itself down so it doesn't restart the time sequence. Still the same problem, but the prefixes worked perfectly.

Also I realize I placed the clock control starter timer in the "After entering room," and not "After entering room for the first time."

Liam315
25 Jul 2013, 09:36
Did you comment out the script on purpose? The scripts were entered in the timer in a comment rather than pasted directly in code view and so wouldn't have been doing anything. If not, I'm not 100% sure what the problem was but I've got it working now. I deleted the second timer, and set the controltimer to be enabled once the intro is read and the previous turn cleared.

Weezil_Of_Mods
25 Jul 2013, 18:49
...Well, now I feel stupid. I didn't think to use an if/then script. Fairly new to 5.4, so there's a bit I don't know. But when you posted the script, I thought it belonged in "comment," because I didn't think of any other place for it.

Many thanks for your help.

Liam315
25 Jul 2013, 21:57
Anywhere you can add a script in Quest, you'll see an icon (next to the "paste" icon) that looks like a white, square piece of paper. By clicking that you switch to code view rather than the graphical versions of each type of script. It's easier to copy from this code view to post on the forums and vice versa than it is to describe each part of a script individually.