Manual:DIL Manual/beginedit()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:21, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

beginedit()

Procedure. Lets a player type several lines of text, which the program then gets.

beginedit(pc : unitptr)

Puts the player in the line editor: they are told "Terminate with a '@'." and what they type from then on is collected instead of being run as commands, until they type a line that ends in @. The text then comes to the program as an SFB_EDIT event, with the lines joined by <br/> and in argument. Use it for longer texts: bug reports, descriptions, board messages.

While the player is in the editor, their editing field is true.

Parameters

Name Type Meaning
pc unitptr The player who writes. Must be a connected player.

Notes

  • Wait for the text right after the call: wait(SFB_EDIT, self == activator); then
 read argument. The event's activator is the unit whose program called
 beginedit(), not the player; with a player's own command (self is the player)
 they are the same.
  • The @ ends the text only as the last character of a line, and is not part of
 the text. The whole text is cut at about 12,000 characters ("String too long - Truncated.").
  • With an NPC, or a player with no connection (link-dead), the program stops with a type
 error in the zone's log. A null pc is only logged.
  • To take a player out of the editor before they finish, use
 killedit. If the unit that called beginedit() is destroyed,
 the editor ends with it ("Unit was extracted, sorry.").
  • Don't call it for a player who is already in the editor (test pc.editing): what
 they wrote so far is lost, and the new text never reaches the program.

Example

dilbegin cmd_report(arg : string);
var
   t : string;
   i : integer;
code
{
   if (self.type != UNIT_ST_PC)
      quit;
   sendtext("Write your report. End it with @ on the last line.<br/>", self);
   beginedit(self);
   wait(SFB_EDIT, self == activator);
   t := argument;
   if (length(getwords(t)) < 2)
   {
      sendtext("Too short, nothing saved.<br/>", self);
      quit;
   }
   i := flog("reports", self.name + " " + asctime(realtime) + "<br/>" + t + "<br/>", "a");
   sendtext("Thank you.<br/>", self);
   quit;
}
dilend

A player command that takes a report of several lines and adds it to a log file, like the bug command in commands.zon.

See also