ID:167399
 
I want to make my own time and date system. There's 20 seconds in a minute, 10 minutes in an hour, and 40 hours in a day. Then there's 21 days in a moon, except the last moon of the year which is the 20th.

Updating the time starts when the map is created.
(there's probably tons of inefficient code)
world
New()
..()
spawn(1)
timeupdate()
spawn(1)
slowtime()
loop_checks = 0

proc
timeupdate()
wseconds += 1
if(wseconds == 20)
wseconds = 0
wminutes += 1
if(wminutes == 10)
wminutes = 0
whours += 1
if(whours == 40)
whours = 0
wday += 1
if(wmoon < 20)
if(wday >= 22)
wday = 0
wmoon += 1
if(wmoon >= 20)
if(wday >= 23)
wday = 0
wmoon = 0
wyear += 1
wtime = "[whours]:[wminutes]:[wseconds]"
wdate = "\Roman[wmoon]/[wday]/[wyear]"
sleep(timespeed)
timeupdate()

After a while, it crashes because it's infinite. I decided to slow time every 2 game hours.(guess there's a kink in gravity)
    slowtime()
timespeed = 1
sleep(400)
timespeed = 10
sleep(4000)
slowtime()

I also have a clock in the top left corner which shows the time using these procs.
        Login()
var/obj/clock/clock/C = new()
src.client.screen += C
src.clockc = C
var/obj/clock/seconds/S = new()
src.client.screen += S
src.secondshand = S
var/obj/clock/minutes/M = new()
src.client.screen += M
src.minuteshand = M
var/obj/clock/hours/H = new()
src.client.screen += H
src.hourshand = H
..()
spawn(1)
S.secondsupdate()
spawn(1)
M.minutesupdate()
spawn(1)
H.hoursupdate()


obj
clock
name = "clock"
icon = 'clock.dmi'
screen_loc = "1,11"
clock
layer = MOB_LAYER+2
icon_state = "clock"
seconds
layer = MOB_LAYER+5
proc
secondsupdate()
src.icon_state = "s[wseconds]"
sleep(timespeed)
src.secondsupdate()
minutes
layer = MOB_LAYER+4
proc
minutesupdate()
src.icon_state = "m[wminutes]"
sleep(timespeed*10)
src.minutesupdate()
hours
icon = 'hours.dmi'
layer = MOB_LAYER+3
proc
hoursupdate()
if(whours > 19)
src.icon_state = "h[whours - 20]"
else
src.icon_state = "h[whours]"
sleep(timespeed*100)
src.hoursupdate()

DreamSeeker will crash after a few game hours have passed. It says something about the system stack, and I guess as a proc loops, it doesn't really "empty".
Is there any way of keeping this time system without needing a reboot every few game hours? A reboot isn't that bad. I was planning the reboot for every game year though.
It's crashing because the proc never ends. You need to spawn() out of the proc before you call itself again, otherwise the system will run out of resources.

For example, in this proc:

            proc
secondsupdate()
src.icon_state = "s[wseconds]"
sleep(timespeed)
src.secondsupdate()


You should use spawn() instead of sleep, and then indent everything after that.

            proc
secondsupdate()
src.icon_state = "s[wseconds]"
spawn(timespeed)
src.secondsupdate()


~~> Unknown Person
In response to Unknown Person
Will this slow game-time if there's a ton going on? I don't mind that. If everyone is lagging and time's lagging, it doesn't make a difference. It actually makes it a little better.