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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= changecolor() =
 +
'''Function''' (integer). Changes one of a player's own colours.
  
 +
changecolor(pc : unitptr, key : string, colour : string)
  
−
<span id="bpchangecolor"></span>
+
Gives the player's colour <code>key</code> the new value <code>colour</code>. It only changes a
 +
colour the player already has (from the <code>color</code> command or
 +
[[Manual:DIL Manual/addcolor()|addcolor()]]); it doesn't add one.
  
−
'''Function: '''<i><!--CODE-->changecolor (ch : unitptr, ks : string, cstr : string ) ;</i><!--ENDCODE-->
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| pc || unitptr || The player. Must be a PC.
 +
|-
 +
| key || string || The colour's name: 1 to 20 letters, digits or <code>_</code>.
 +
|-
 +
| colour || string || The new colour, such as <code>"cpc bn"</code> (see [[Manual:DIL Manual/addcolor()|addcolor()]]).
 +
|}
  
−
<!--TERM--> '''ch'''
+
== Returns ==
−
<!--DEFINITION-->         character you are changing the color on
+
Integer: <code>TRUE</code> when the colour was changed, <code>FALSE</code> when the player has
−
<!--TERM--> '''ks'''
+
no such key. It fails, and writes a line to the zone's log, when <code>pc</code> is null or not
−
<!--DEFINITION-->         key string for the color
+
a PC, when the key is empty, too long or has other characters, or when <code>colour</code> is
−
<!--TERM--> '''cstr'''
+
empty.
−
<!--DEFINITION-->         color string
 
  
−
This will change a color in a players personal list.
+
== Notes ==
−
'''Function:  '''<i><!--CODE-->changecolor(pc, "clan_who","&amp;c+w&amp;bn");</i><!--ENDCODE-->
+
* A key is matched by abbreviation: <code>changecolor(pc, "cl", ...)</code> changes the
 +
  player's first key that begins with ''cl''.
 +
* The colour isn't checked; see [[Manual:DIL Manual/addcolor()|addcolor()]] for the values the
 +
  <code>color</code> command accepts.
 +
* Personal colours only change what telnet players see.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin clan_col_cmd(arg : string);
 +
var
 +
  i : integer;
 +
code
 +
{
 +
  if (arg == "")
 +
  {
 +
      sendtext("Which colour? For example: clancolor cpc bn<br/>", self);
 +
      quit;
 +
  }
 +
 
 +
  i := changecolor(self, "clan_who", arg);
 +
  if (i == FALSE)
 +
      i := addcolor(self, "clan_who", arg);
 +
 
 +
  sendtext(getcolor("clan_who") + "Like this?</div><br/>", self);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
A player command <code>clancolor &lt;colour&gt;</code> that changes the player's
 +
<code>clan_who</code> colour, or adds it the first time.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/addcolor()|addcolor()]]
 +
* [[Manual:DIL Manual/delcolor()|delcolor()]]
 +
* [[Manual:DIL Manual/getcolor()|getcolor()]]

Latest revision as of 23:04, 14 November 2026

changecolor()

Function (integer). Changes one of a player's own colours.

changecolor(pc : unitptr, key : string, colour : string)

Gives the player's colour key the new value colour. It only changes a colour the player already has (from the color command or addcolor()); it doesn't add one.

Parameters

Name Type Meaning
pc unitptr The player. Must be a PC.
key string The colour's name: 1 to 20 letters, digits or _.
colour string The new colour, such as "cpc bn" (see addcolor()).

Returns

Integer: TRUE when the colour was changed, FALSE when the player has no such key. It fails, and writes a line to the zone's log, when pc is null or not a PC, when the key is empty, too long or has other characters, or when colour is empty.

Notes

  • A key is matched by abbreviation: changecolor(pc, "cl", ...) changes the
 player's first key that begins with cl.
  • The colour isn't checked; see addcolor() for the values the
 color command accepts.
  • Personal colours only change what telnet players see.

Example

dilbegin clan_col_cmd(arg : string);
var
   i : integer;
code
{
   if (arg == "")
   {
      sendtext("Which colour? For example: clancolor cpc bn<br/>", self);
      quit;
   }

   i := changecolor(self, "clan_who", arg);
   if (i == FALSE)
      i := addcolor(self, "clan_who", arg);

   sendtext(getcolor("clan_who") + "Like this?</div><br/>", self);
   quit;
}
dilend

A player command clancolor <colour> that changes the player's clan_who colour, or adds it the first time.

See also