Difference between revisions of "Manual:DIL Manual/realtime"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bvrealtime"></span>
+
= realtime =
−
'realtime'
+
'''Variable''' (integer, read-only).
−
    This variable returns the number of seconds passed since 1970 something.
 
−
    For C buffs this is equivalent to time(NULL).
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  realtime : integer
−
<span id="bvrealtime"></span>
 
−
'realtime'
 
−
    This variable returns the number of seconds passed since 1970 something.
 
−
    For C buffs this is equivalent to time(NULL).
 
  
−
---~---~---~---~---~---~---~---~---
+
The real time, in seconds since 1 January 1970 UTC: what <code>time(NULL)</code> gives in C.
 +
 
 +
== Notes ==
 +
* It is the real clock: <code>vme -w</code> and <code>wtimewarp</code> don't move it, unlike mudhour and the other mud-time variables.
 +
* asctime() turns it into a readable date: <code>asctime(realtime)</code>.
 +
* <code>pc.birth</code> is on the same clock, so <code>realtime - pc.birth</code> is a player's age in real seconds.
 +
* To keep a moment across reboots or on a unit, store <code>itoa(realtime)</code> in an extra and compare with <code>atoi()</code> later, as death.zon does with severed heads.
 +
* It is a 32-bit signed integer, so it overflows on 19 January 2038.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin rot_away();
 +
var
 +
  e : extraptr;
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 15;
 +
  if (self.extra.["$made"] == null)
 +
      addextra(self.extra, {"$made"}, itoa(realtime));
 +
 
 +
  :loop:
 +
  pause;
 +
  e := "$made" in self.extra;
 +
  if (e == null)
 +
      goto loop;
 +
  if ((realtime - atoi(e.descr)) > 1800)
 +
  {
 +
      act("$1n rots away.", A_SOMEONE, self, null, null, TO_ROOM);
 +
      destroy(self);
 +
      quit;
 +
  }
 +
  goto loop;
 +
}
 +
dilend
 +
</pre>
 +
An object that rots away half an hour (1800 real seconds) after it first ran, as the heads in death.zon. The extra is looked up again after each pause, because extra variables are cleared at every wake.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/asctime()|asctime()]]
 +
* [[Manual:DIL Manual/birth|birth]]
 +
* [[Manual:DIL Manual/addextra()|addextra()]]
 +
* [[Manual:DIL Manual/mudhour|mudhour]]

Latest revision as of 23:19, 14 November 2026

realtime

Variable (integer, read-only).

realtime : integer

The real time, in seconds since 1 January 1970 UTC: what time(NULL) gives in C.

Notes

  • It is the real clock: vme -w and wtimewarp don't move it, unlike mudhour and the other mud-time variables.
  • asctime() turns it into a readable date: asctime(realtime).
  • pc.birth is on the same clock, so realtime - pc.birth is a player's age in real seconds.
  • To keep a moment across reboots or on a unit, store itoa(realtime) in an extra and compare with atoi() later, as death.zon does with severed heads.
  • It is a 32-bit signed integer, so it overflows on 19 January 2038.

Example

dilbegin rot_away();
var
   e : extraptr;
code
{
   heartbeat := PULSE_SEC * 15;
   if (self.extra.["$made"] == null)
      addextra(self.extra, {"$made"}, itoa(realtime));

   :loop:
   pause;
   e := "$made" in self.extra;
   if (e == null)
      goto loop;
   if ((realtime - atoi(e.descr)) > 1800)
   {
      act("$1n rots away.", A_SOMEONE, self, null, null, TO_ROOM);
      destroy(self);
      quit;
   }
   goto loop;
}
dilend

An object that rots away half an hour (1800 real seconds) after it first ran, as the heads in death.zon. The extra is looked up again after each pause, because extra variables are cleared at every wake.

See also