Difference between revisions of "Manual:DIL Manual/act()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = act() = | |
| + | '''Procedure.''' Shows a message to the characters around someone, worded for each of them. | ||
| − | + | act(text : string, show : integer, char : unitptr, medium : unitptr or string, | |
| − | + | victim : unitptr or string, to : integer) | |
| − | |||
| − | |||
| + | Sends <code>text</code> to the characters that <code>to</code> picks, around <code>char</code>. Codes such as <code>$1n</code> in the text are filled in for each reader: a name, or "someone" when they can't see who it is, "he" or "she", and so on. The usual way to tell what happens is one act for the one who does it (<code>TO_CHAR</code>), one for the victim (<code>TO_VICT</code>) and one for the others (<code>TO_NOTVICT</code> or <code>TO_REST</code>). | ||
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | text || string || The message, with $-codes (below). No <code><br/></code> at the end: act adds it. | ||
| + | |- | ||
| + | | show || integer || <code>A_SOMEONE</code>, <code>A_HIDEINV</code>, <code>A_ALWAYS</code> or <code>A_RAW</code> (below). | ||
| + | |- | ||
| + | | char || unitptr || The one who acts: <code>$1</code>, and the place the message goes out from. | ||
| + | |- | ||
| + | | medium || unitptr or string || <code>$2</code>: a unit, a string for <code>$2t</code>, or <code>null</code>. | ||
| + | |- | ||
| + | | victim || unitptr or string || <code>$3</code>: a unit, a string for <code>$3t</code>, or <code>null</code>. | ||
| + | |- | ||
| + | | to || integer || Who gets it: a <code>TO_</code> constant (below). | ||
| + | |} | ||
| − | + | The constants are in <code>vme.h</code>. | |
| − | + | {| class="wikitable" | |
| + | ! to !! Who gets it | ||
| + | |- | ||
| + | | TO_CHAR || <code>char</code> only. | ||
| + | |- | ||
| + | | TO_VICT || <code>victim</code> only. | ||
| + | |- | ||
| + | | TO_ROOM || Everyone around <code>char</code>, but not <code>char</code>. | ||
| + | |- | ||
| + | | TO_NOTVICT || Everyone around <code>char</code>, but not <code>char</code> and not <code>victim</code>. | ||
| + | |- | ||
| + | | TO_ALL || Everyone around <code>char</code>, <code>char</code> too. | ||
| + | |- | ||
| + | | TO_REST || As <code>TO_ROOM</code>, and not those inside <code>char</code> either. | ||
| + | |} | ||
| + | "Around <code>char</code>" is the room <code>char</code> is in, including those inside transparent units there; when <code>char</code> is inside a transparent unit (a wagon, a boat), also the room around that unit. | ||
| + | {| class="wikitable" | ||
| + | ! show !! Meaning | ||
| + | |- | ||
| + | | A_SOMEONE || Not shown to those asleep. A unit a reader can't see is "someone" or "something". | ||
| + | |- | ||
| + | | A_HIDEINV || Not shown to those who can't see <code>char</code>, nor to those asleep. For things that are only seen, like a smile. | ||
| + | |- | ||
| + | | A_ALWAYS || Shown also to those asleep. A unit a reader can't see is "someone" or "something". | ||
| + | |- | ||
| + | | A_RAW || Shown to everyone, and <code>$n</code> and <code>$N</code> give the real names even of units the reader can't see. | ||
| + | |} | ||
| − | + | A code is <code>$</code>, a digit for the argument (1 <code>char</code>, 2 <code>medium</code>, 3 <code>victim</code>) and a letter: | |
| − | + | {| class="wikitable" | |
| − | + | ! Code !! Becomes | |
| − | + | |- | |
| − | + | | $1n || A player's name, or the title of an NPC or object ("the town guard"); "someone" or "something" to those who can't see it. | |
| − | + | |- | |
| − | + | | $1N || The unit's first name ("guard"); "someone" or "something" to those who can't see it. | |
| − | + | |- | |
| − | + | | $1e, $1m, $1s || he/she/it, him/her/it, his/her/its. | |
| − | + | |- | |
| − | + | | $1p || The character's position (standing, sleeping, ...); "lying" for anything else. | |
| − | + | |- | |
| − | + | | $1a || "a" or "an" to go before the unit's name (or before a string argument). | |
| − | + | |- | |
| − | + | | $2t || The string given as that argument. | |
| − | + | |- | |
| − | + | | $$ || A single <code>$</code>. | |
| − | + | |} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| + | * Only characters with a connection see it. NPCs, and the programs on them, never see act() text: to tell a program something, use <code>send()</code> or <code>sendto()</code>. | ||
| + | * With <code>char</code> null, or <code>victim</code> null for <code>TO_VICT</code> and <code>TO_NOTVICT</code>, nothing is sent. A string as <code>char</code> compiles but sends nothing. | ||
| + | * A <code>to</code> outside <code>TO_ROOM</code> ... <code>TO_REST</code> (0 to 5) sends nothing. A <code>show</code> below 10 or above 14 is logged and taken as <code>A_ALWAYS</code>. | ||
| + | * A code whose argument is null shows "NULL", and an unknown code cuts the message there; both are logged. | ||
| + | * The first letter is made a capital (after any HTML tags at the start). | ||
| + | * Numbers can't be passed: give <code>itoa(n)</code> as the medium or victim and write <code>$2t</code> or <code>$3t</code>. | ||
| + | * Used in an expression, <code>s := act(...)</code> sends nothing and gives the text as the one it is about would see it, with the <code><br/></code>, or <code>""</code> when there is nobody or they wouldn't see it; see <code>sact()</code>. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| + | dilbegin block_flee(); | ||
| + | var | ||
| + | pc : unitptr; | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_CMD, command("flee") and (activator.type == UNIT_ST_PC)); | ||
| + | pc := activator; | ||
| + | block; | ||
| + | act("You panic and try to flee, but something prevents you from escaping!", | ||
| + | A_SOMEONE, pc, null, self, TO_CHAR); | ||
| + | act("$1n panics and tries to flee, but can not!", | ||
| + | A_SOMEONE, pc, null, self, TO_REST); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| − | + | dilbegin hand_over(item : unitptr, pc : unitptr); | |
| − | + | code | |
| − | + | { | |
| + | act("You hand $2n to $3n.", A_SOMEONE, self, item, pc, TO_CHAR); | ||
| + | act("$1n hands you $2n.", A_SOMEONE, self, item, pc, TO_VICT); | ||
| + | act("$1n hands $2n to $3n.", A_SOMEONE, self, item, pc, TO_NOTVICT); | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Fleeing fails where this program is, with one message for the player and one for the others (adapted from clans.zon), and the three messages of handing something over. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/sact()|sact()]] | |
| − | + | * [[Manual:DIL Manual/sendtext()|sendtext()]] | |
| − | + | * [[Manual:DIL Manual/send()|send()]] | |
| − | + | * [[Manual:DIL Manual/sendto()|sendto()]] | |
| − | + | * [[Manual:DIL Manual/itoa()|itoa()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:22, 14 November 2026
act()
Procedure. Shows a message to the characters around someone, worded for each of them.
act(text : string, show : integer, char : unitptr, medium : unitptr or string,
victim : unitptr or string, to : integer)
Sends text to the characters that to picks, around char. Codes such as $1n in the text are filled in for each reader: a name, or "someone" when they can't see who it is, "he" or "she", and so on. The usual way to tell what happens is one act for the one who does it (TO_CHAR), one for the victim (TO_VICT) and one for the others (TO_NOTVICT or TO_REST).
Parameters
| Name | Type | Meaning |
|---|---|---|
| text | string | The message, with $-codes (below). No <br/> at the end: act adds it.
|
| show | integer | A_SOMEONE, A_HIDEINV, A_ALWAYS or A_RAW (below).
|
| char | unitptr | The one who acts: $1, and the place the message goes out from.
|
| medium | unitptr or string | $2: a unit, a string for $2t, or null.
|
| victim | unitptr or string | $3: a unit, a string for $3t, or null.
|
| to | integer | Who gets it: a TO_ constant (below).
|
The constants are in vme.h.
| to | Who gets it |
|---|---|
| TO_CHAR | char only.
|
| TO_VICT | victim only.
|
| TO_ROOM | Everyone around char, but not char.
|
| TO_NOTVICT | Everyone around char, but not char and not victim.
|
| TO_ALL | Everyone around char, char too.
|
| TO_REST | As TO_ROOM, and not those inside char either.
|
"Around char" is the room char is in, including those inside transparent units there; when char is inside a transparent unit (a wagon, a boat), also the room around that unit.
| show | Meaning |
|---|---|
| A_SOMEONE | Not shown to those asleep. A unit a reader can't see is "someone" or "something". |
| A_HIDEINV | Not shown to those who can't see char, nor to those asleep. For things that are only seen, like a smile.
|
| A_ALWAYS | Shown also to those asleep. A unit a reader can't see is "someone" or "something". |
| A_RAW | Shown to everyone, and $n and $N give the real names even of units the reader can't see.
|
A code is $, a digit for the argument (1 char, 2 medium, 3 victim) and a letter:
| Code | Becomes |
|---|---|
| $1n | A player's name, or the title of an NPC or object ("the town guard"); "someone" or "something" to those who can't see it. |
| $1N | The unit's first name ("guard"); "someone" or "something" to those who can't see it. |
| $1e, $1m, $1s | he/she/it, him/her/it, his/her/its. |
| $1p | The character's position (standing, sleeping, ...); "lying" for anything else. |
| $1a | "a" or "an" to go before the unit's name (or before a string argument). |
| $2t | The string given as that argument. |
| $$ | A single $.
|
Notes
- Only characters with a connection see it. NPCs, and the programs on them, never see act() text: to tell a program something, use
send()orsendto(). - With
charnull, orvictimnull forTO_VICTandTO_NOTVICT, nothing is sent. A string ascharcompiles but sends nothing. - A
tooutsideTO_ROOM...TO_REST(0 to 5) sends nothing. Ashowbelow 10 or above 14 is logged and taken asA_ALWAYS. - A code whose argument is null shows "NULL", and an unknown code cuts the message there; both are logged.
- The first letter is made a capital (after any HTML tags at the start).
- Numbers can't be passed: give
itoa(n)as the medium or victim and write$2tor$3t. - Used in an expression,
s := act(...)sends nothing and gives the text as the one it is about would see it, with the<br/>, or""when there is nobody or they wouldn't see it; seesact().
Example
dilbegin block_flee();
var
pc : unitptr;
code
{
:start:
wait(SFB_CMD, command("flee") and (activator.type == UNIT_ST_PC));
pc := activator;
block;
act("You panic and try to flee, but something prevents you from escaping!",
A_SOMEONE, pc, null, self, TO_CHAR);
act("$1n panics and tries to flee, but can not!",
A_SOMEONE, pc, null, self, TO_REST);
goto start;
}
dilend
dilbegin hand_over(item : unitptr, pc : unitptr);
code
{
act("You hand $2n to $3n.", A_SOMEONE, self, item, pc, TO_CHAR);
act("$1n hands you $2n.", A_SOMEONE, self, item, pc, TO_VICT);
act("$1n hands $2n to $3n.", A_SOMEONE, self, item, pc, TO_NOTVICT);
return;
}
dilend
Fleeing fails where this program is, with one message for the player and one for the others (adapted from clans.zon), and the three messages of handing something over.