ID:174906
 
how complicated would it be to make a clock in the stat panel that tells how long they have been in the game? can anyone enlighten me on how to do this?
mob/proc/Begin()
src.seconds = 0
src.Start()
mob/proc/Start()
src.seconds ++
src.Check()

mob/Stat()
statpanel("In Game time")
stat("[src.day]:[src.hour]:[src.minutes]:[src.seconds]")

mob/var{hour=1;minutes;=0;seconds=0;day=0}

mob/proc/Check()
if(src.seconds == 60)
src.minutes ++
src.seconds = 0
if(src.minutes == 60)
src.hour ++
src.minutes = 0
if(src.hour == 24)
src.day ++
src.hour = 1
spawn(10) Start()
mob/Login
Start()
..()
In response to Super16
If you changed the ++s to --s could this work as a countdown?

Airjoe
In response to Airjoe
probably but it would reset.
In response to Siefer
Reset? I just need a count-down timer, and I was about to post when I saw Super16's post.
In response to Airjoe
ok the clock code works right and everything but when i log back in with my character the clock is stopped.
In response to Siefer
i fixed it nm
In response to Super16
Super16 wrote:
mob/proc/Begin()
src.seconds = 0
src.Start()
mob/proc/Start()
src.seconds ++
src.Check()

mob/Stat()
statpanel("In Game time")
stat("[src.day]:[src.hour]:[src.minutes]:[src.seconds]")

mob/var{hour=1;minutes;=0;seconds=0;day=0}

mob/proc/Check()
if(src.seconds == 60)
src.minutes ++
src.seconds = 0
if(src.minutes == 60)
src.hour ++
src.minutes = 0
if(src.hour == 24)
src.day ++
src.hour = 1
spawn(10) Start()
mob/Login
Start()
..()

There are a lot of problems with this approach, the first being that you've paid no attention to formatting. The output could look like 1:2:3:4, which isn't very clock-like.

Also, it's better to simply use world.time and an offset instead of spawning a proc constantly; you'll just end up wasting a lot of time. (Plus there's a spawn() bug in BYOND that will screw up the timing of the clock anyway.)

In Stat(), what you'd want to do is this:
mob
var/logintime = 0

Login()
logintime = world.time - 5 // -5 is for rounding purposes
..()

Stat()
var/elapsed = world.time - logintime
stat("Logged in for","[round(elapsed/36000)]:\
[elapsed/6000%6][elapsed/600%10]:\
[elapsed/100%6][elapsed/10%10]")
The result of that will look like 0:03:45, which is much nicer. I didn't bother to separate hours and days because for the most part that won't ever matter.

Lummox JR