ID:155003
 
Hi, i would like my game to have its own "in-game clock"

problem is i have no idea where to read how i would do something like that..

I have seen one Poke'mon game use its own in-game clock for catching poke'mon that only appear at night so i know its possible i just dont know where to learn how to do it..
I'll give you a few hints:
timeofday var, realtime var and the time2text() proc.
In response to Raimo
Ty :D
In response to NotS
Ok so um...i dont think this is what im looking for..

Im talking about creating my own in-game time...not a realtime clock, i think i should of said that...sorry

I would like to make it so my game has its own in-game time separate from real time so say 12 midnight happens every 30 min

is that possible? if so how would i learn to do it?
In response to NotS

You can instead then create your own customized clock!

var
hour //a variable that doesn't belong to anyone in particular

world
New() //when the world is created
..()
Clock() //start the clock procedure

proc
Clock()
spawn while(src) //while the world exists, and spawn allows other things to\
happen at the same time

sleep(10) //every second is equivelent to one hour in this example
hour ++

if(hour > 24) //if we've reached 24 hours, go back to the beginning
hour = 0


mob
New() //This is just an example of how the hour can be checked
..()
if(hour < 12) //if its the morning
icon = 'morning creature.dmi' //obviously this probably isn't what you want,
else //if its night
icon = 'night time creature.dmi' //since all mobs on creation will become one or\
the other when created. However hopefully you get the idea of how hour is checked.





Obviously I hope by the example you can see it is possible to check for minutes, hours, how often this is updated by sleep(), and all that. :)
In response to Speedro
:D i thought of using the sleep proc but since im so new to DM programming i didnt know where to start. thats a cool little code.
This is what my program K-DOS uses :

proc/get_time()
time = ("[days]:[hours]:[minutes]:[seconds] ")

proc/get_date()
var/http = world.Export("http://Byond.com")
date = http["DATE"]

var
core_time = 0
seconds = 0
minutes = 0
hours = 0
days = 0
time
date

world

New()
spawn() // Update Date //
while(src)
get_date()

spawn() // Run Core Clock //
while(src)
sleep(10)
core_time ++
if(seconds <= 58)
seconds ++
else
seconds = 0
if(minutes <= 58)
minutes ++
else
minutes = 0
hours ++
if(hours <= 58)
hours ++
else
hours = 0
days ++
get_time()


Source : http://www.byond.com/developer/Kyle_ZX/KDOS

Basically get_time() will return something like "0 : 0 : 0 : 22" which is used to display the time. So a loop that uses get_time() will keep it updated.

core_time the variable will always give the exact time in seconds. It would equal something like 27473 and will increase every second the game is working.

Get_Date is a little harder to use in the skin but you can. It will return a result like "21 Feburary 2011" and updates every 4 to 7 seconds. I use it like this :

        spawn() // Title
while(src)
winset(src,"main","title = \"K-DOS Date : [date] Core Time : [time]")
sleep(1)


All of this culminates to give :



Hope this helps.
In response to Kyle_ZX
Why exactly are you using an HTTP query to determine the date, instead of using BYOND's built-in realtime/time/timeofday variables in conjunction with time2text? This isn't something you should really be telling someone that's new to the language to do.
In response to Audeuro
Haha, not something I knew how to do. I just found that if I checked for the Date variable that's what I got.
In response to Kyle_ZX
The way you're doing it is a serious waste of bandwidth (Have you checked the size of BYOND's home page recently?) and you should probably change the way you do it. The proper way to work with time and date most of the time is to use world.realtime and world.timeofday. You can use world.timeofday to get a more precise time for minutes, seconds, and hours, and you can use world.realtime for the months, years, and days. You can also convert either of these variables to text strings using time2text.