Difference between revisions of "Manual:DIL Manual/delunit()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(store() removes the file itself when there is nothing to save)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
−
<span id="bfdelunit"></span>
+
= delunit() =
 +
'''Function''' (integer). Deletes a unit file.
  
−
  '''Function:'''  <i><!--CODE-->integer delunit( filename : string ) ;</i><!--ENDCODE-->
+
  delunit(filename : string)
  
−
<!--TERM-->  '''filename'''
+
Deletes a file written by [[Manual:DIL Manual/store()|store()]]. A file that
−
<!--DEFINITION-->        The name of the Unit file to be deleted.
+
[[Manual:DIL Manual/restore()|restore()]] has loaded is still there, and would be loaded again;
−
<!--TERM-->  '''Return'''
+
delete it once it has served, as death.zon does with corpse files and mail.zon with parcels.
−
<!--DEFINITION-->        Returns an integer TRUE if deleted FALSE if not delunit is used to delete files that are used with the 'Restore' and 'store' functions.
 
  
−
'''Example:'''
+
== Parameters ==
−
<i><!--CODE-->
+
{| class="wikitable"
−
---~---~---~---~---~---~---~---~---
+
! Name !! Type !! Meaning
 +
|-
 +
| filename || string || The file's name, as given to <code>store()</code>: letters, digits, <code>_</code> and <code>.</code> only, at most 512 characters.
 +
|}
  
−
dilbegin chest_del ("arg : string /*filename to be deleted*/);
+
== Returns ==
−
var
+
integer. As the server is now, FALSE (0) when the file was deleted and TRUE (1) when it wasn't (no such file); the opposite of what the name suggests. FALSE as well for a name with other characters. Don't rely on the value: no zone does, and it may be corrected.
−
        ret:integer;/*to hold the return value if deleted or not*/
 
−
code
 
−
dilend
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
'''See Also'''
 
−
[[#bfrestore|Restore a Unit from a Unit file]] and
 
−
[[#bpstore|Store Units to a Unit file]].
 
−
 
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bfdelunit"></span>
 
−
 
 
−
'''Function:'''  <i><!--CODE-->integer delunit( filename : string ) ;</i><!--ENDCODE-->
 
  
−
<!--TERM--> '''filename'''
+
== Notes ==
−
<!--DEFINITION-->         The name of the Unit file to be deleted.
+
* The file is in the <code>units</code> folder of the zone's DIL file directory (the last column of the zone's line in <code>vme/etc/zonelist</code>), or of <code>dil_file_dir</code> in <code>server.cfg</code> when the zone has none.
−
<!--TERM--> '''Return'''
+
* Only zones with access level 10 or less (the fourth column of <code>zonelist</code>) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (delunit)".
−
<!--DEFINITION-->         Returns an integer TRUE if deleted FALSE if not delunit is used to delete files that are used with the 'Restore' and 'store' functions.
+
* A name with other characters (a <code>/</code>, a space) is refused with a line in the zone log.
 +
* <code>store()</code> removes the file itself when there is nothing to save, so emptying a container and storing it again is enough.
  
−
'''Example:'''
+
== Example ==
−
<i><!--CODE-->
+
<pre>
−
---~---~---~---~---~---~---~---~---
+
dilbegin fetch_parcel(pc : unitptr);
−
 
+
var
−
dilbegin chest_del ("arg : string /*filename to be deleted*/);
+
  fn : string;
−
var
+
  u : unitptr;
−
        ret:integer;/*to hold the return value if deleted or not*/
+
  i : integer;
−
code
+
code
 +
{
 +
  fn := tolower(pc.name) + ".parcel";
 +
  u := restore(fn, pc);
 +
  if (u == null)
 +
  {
 +
      sendtext("There is no parcel for you.<br/>", pc);
 +
      return;
 +
  }
 +
  i := delunit(fn);               // so it can't be fetched twice
 +
  act("You receive $2n.", A_ALWAYS, pc, u, null, TO_CHAR);
 +
  return;
 +
}
 
dilend
 
dilend
 +
</pre>
 +
Gives a player the parcel stored for them (see [[Manual:DIL Manual/store()|store()]]) and deletes the file.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/store()|store()]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/restore()|restore()]]
−
'''See Also'''
+
* [[Manual:DIL Manual/delstr()|delstr()]]
−
[[#bfrestore|Restore a Unit from a Unit file]] and
 
−
[[#bpstore|Store Units to a Unit file]].
 
−
 
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 12:35, 19 November 2026

delunit()

Function (integer). Deletes a unit file.

delunit(filename : string)

Deletes a file written by store(). A file that restore() has loaded is still there, and would be loaded again; delete it once it has served, as death.zon does with corpse files and mail.zon with parcels.

Parameters

Name Type Meaning
filename string The file's name, as given to store(): letters, digits, _ and . only, at most 512 characters.

Returns

integer. As the server is now, FALSE (0) when the file was deleted and TRUE (1) when it wasn't (no such file); the opposite of what the name suggests. FALSE as well for a name with other characters. Don't rely on the value: no zone does, and it may be corrected.

Notes

  • The file is in the units folder of the zone's DIL file directory (the last column of the zone's line in vme/etc/zonelist), or of dil_file_dir in server.cfg when the zone has none.
  • Only zones with access level 10 or less (the fourth column of zonelist) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (delunit)".
  • A name with other characters (a /, a space) is refused with a line in the zone log.
  • store() removes the file itself when there is nothing to save, so emptying a container and storing it again is enough.

Example

dilbegin fetch_parcel(pc : unitptr);
var
   fn : string;
   u : unitptr;
   i : integer;
code
{
   fn := tolower(pc.name) + ".parcel";
   u := restore(fn, pc);
   if (u == null)
   {
      sendtext("There is no parcel for you.<br/>", pc);
      return;
   }
   i := delunit(fn);               // so it can't be fetched twice
   act("You receive $2n.", A_ALWAYS, pc, u, null, TO_CHAR);
   return;
}
dilend

Gives a player the parcel stored for them (see store()) and deletes the file.

See also