Difference between revisions of "Manual:DIL Manual/delunit()"
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: | ||
| − | + | = delunit() = | |
| + | '''Function''' (integer). Deletes a unit file. | ||
| − | + | delunit(filename : string) | |
| − | + | 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. | |
| − | |||
| − | + | == 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. | ||
| + | |} | ||
| − | + | == 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 <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. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | 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 | 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()]] | |
| − | + | * [[Manual:DIL Manual/restore()|restore()]] | |
| − | + | * [[Manual:DIL Manual/delstr()|delstr()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
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
unitsfolder of the zone's DIL file directory (the last column of the zone's line invme/etc/zonelist), or ofdil_file_dirinserver.cfgwhen 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.