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

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="bpbeginedit"></span>
+
= beginedit() =
 +
'''Procedure.''' Lets a player type several lines of text, which the program then gets.
  
−
  '''Function:'''  <i><!--CODE-->beginedit ( u : unitptr);</i><!--ENDCODE-->
+
  beginedit(pc : unitptr)
  
−
<!--TERM-->  '''u'''
+
Puts the player in the line editor: they are told "Terminate with a '@'." and what they type
−
<!--DEFINITION-->         the PC unit doing the editing
+
from then on is collected instead of being run as commands, until they type a line that ends
−
<!--TERM--> '''return'''
+
in <code>@</code>. The text then comes to the program as an <code>SFB_EDIT</code> event, with
−
<!--DEFINITION-->         When done  editing it returns SFB_EDIT and activator is set to PC
+
the lines joined by <code>&lt;br/&gt;</code> and in <code>argument</code>. Use it for longer
 +
texts: bug reports, descriptions, board messages.
  
−
The 'BEGINEDIT' function sets a PC into editing mode.  while in edit mode
+
While the player is in the editor, their [[Manual:DIL Manual/editing|editing]] field is true.
−
the PC field 'editing is set to true.  Once the PC is done editing a 'SFB_EDIT'
 
−
message is sent to the unit editing to continue on with the DIL.
 
−
If for some reason the PC needs to break
 
−
out of the editor before it is done editing then the Dil needs to call
 
−
the 'killedit' function
 
−
[[#sect-beginedit|interrupt editing before done]]
 
  
−
'''example:'''
+
== Parameters ==
−
<i><!--CODE-->
+
{| class="wikitable"
−
---~---~---~---~---~---~---~---~---
+
! Name !! Type !! Meaning
 +
|-
 +
| pc || unitptr || The player who writes. Must be a connected player.
 +
|}
  
−
dilbegin edextra ();
+
== Notes ==
−
var
+
* Wait for the text right after the call: <code>wait(SFB_EDIT, self == activator);</code> then
−
        temp:string;
+
  read <code>argument</code>. The event's activator is the unit whose program called
−
code
+
  beginedit(), not the player; with a player's own command (<code>self</code> is the player)
−
dilend
+
  they are the same.
−
 
+
* The <code>@</code> 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
−
</i><!--ENDCODE-->
+
  error in the zone's log. A null <code>pc</code> is only logged.
−
The previous DIL is an example of how you could make a command to set the
+
* To take a player out of the editor before they finish, use
−
general extra which is the characters description when you do 'look player'
+
  [[Manual:DIL Manual/killedit|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 <code>pc.editing</code>): what
−
---~---~---~---~---~---~---~---~---
+
  they wrote so far is lost, and the new text never reaches the program.
−
<span id="bpbeginedit"></span>
 
−
 
 
−
'''Function:'''  <i><!--CODE-->beginedit ( u : unitptr);</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''u'''
 
−
<!--DEFINITION-->        the PC unit doing the editing
 
−
<!--TERM--> '''return'''
 
−
<!--DEFINITION-->         When done  editing it returns SFB_EDIT and activator is set to PC
 
−
 
 
−
The 'BEGINEDIT' function sets a PC into editing mode. while in edit mode
 
−
the PC field 'editing is set to true.  Once the PC is done editing a 'SFB_EDIT'
 
−
message is sent to the unit editing to continue on with the DIL.
 
−
If for some reason the PC needs to break
 
−
out of the editor before it is done editing then the Dil needs to call
 
−
the 'killedit' function
 
−
[[#sect-beginedit|interrupt editing before done]]
 
−
 
 
−
'''example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
  
−
dilbegin edextra ();
+
== Example ==
−
var
+
<pre>
−
        temp:string;
+
dilbegin cmd_report(arg : string);
−
code
+
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
 
dilend
 +
</pre>
 +
A player command that takes a report of several lines and adds it to a log file, like the
 +
<code>bug</code> command in commands.zon.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/killedit|killedit]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/editing|editing]]
−
The previous DIL is an example of how you could make a command to set the
+
* [[Manual:DIL Manual/wait()|wait()]]
−
general extra which is the characters description when you do 'look player'
+
* [[Manual:DIL Manual/argument|argument]]
−
 
+
* [[Manual:DIL Manual/flog()|flog()]]
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:21, 14 November 2026

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