Difference between revisions of "Manual:DIL Manual/beginedit()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = 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 <code>@</code>. The text then comes to the program as an <code>SFB_EDIT</code> event, with | |
| − | + | the lines joined by <code><br/></code> and in <code>argument</code>. Use it for longer | |
| + | texts: bug reports, descriptions, board messages. | ||
| − | + | While the player is in the editor, their [[Manual:DIL Manual/editing|editing]] field is true. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| + | |- | ||
| + | | pc || unitptr || The player who writes. Must be a connected player. | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * Wait for the text right after the call: <code>wait(SFB_EDIT, self == activator);</code> then | |
| − | + | read <code>argument</code>. The event's activator is the unit whose program called | |
| − | + | beginedit(), not the player; with a player's own command (<code>self</code> is the player) | |
| − | + | 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 | |
| − | + | error in the zone's log. A null <code>pc</code> is only logged. | |
| − | + | * To take a player out of the editor before they finish, use | |
| − | + | [[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. | |
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | 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 | 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]] | |
| − | + | * [[Manual:DIL Manual/editing|editing]] | |
| − | + | * [[Manual:DIL Manual/wait()|wait()]] | |
| − | + | * [[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
readargument. The event's activator is the unit whose program called beginedit(), not the player; with a player's own command (selfis 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.