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)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
= delunit() =
 +
'''Function''' (integer). Deletes a unit file.
  
 +
delunit(filename : string)
  
−
<span id="bfdelunit"></span>
+
Deletes a file written by [[Manual:DIL Manual/store()|store()]]. A file that
 +
[[Manual:DIL Manual/restore()|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.
  
−
'''Function:'''  <i><!--CODE-->integer delunit( filename : string ) ;</i><!--ENDCODE-->
+
== Parameters ==
 +
{| 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.
 +
|}
  
−
<!--TERM-->  '''filename'''
+
== Returns ==
−
<!--DEFINITION-->        The name of the Unit file to be deleted.
+
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.
−
<!--TERM-->  '''Return'''
 
−
<!--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:'''
+
== Notes ==
−
<i><!--CODE-->
+
* 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.
−
---~---~---~---~---~---~---~---~---
+
* 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)".
 +
* 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.
  
−
dilbegin chest_del ("arg : string /*filename to be deleted*/);
+
== Example ==
−
var
+
<pre>
−
        ret:integer;/*to hold the return value if deleted or not*/
+
dilbegin fetch_parcel(pc : unitptr);
−
code
+
var
−
{
+
  fn : string;
−
ret:= delstr("chest.file");
+
  u : unitptr;
−
if (!ret)
+
  i : integer;
−
        {
+
code
−
        log ("File not deleted.");
+
{
−
        quit;
+
  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
 +
</pre>
 +
Gives a player the parcel stored for them (see [[Manual:DIL Manual/store()|store()]]) and deletes the file.
  
−
sendtext("Chest file deleted[&amp;]n",self);
+
== See also ==
−
quit;/*dil delete routine done
+
* [[Manual:DIL Manual/store()|store()]]
−
}
+
* [[Manual:DIL Manual/restore()|restore()]]
−
dilend
+
* [[Manual:DIL Manual/delstr()|delstr()]]
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
'''See Also'''
 
−
[[#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