Welcome to the Builder Academy

Question Color

More
12 May 2017 13:34 #6724 by Preach
Color was created by Preach
Is there a way to use a trigger in the text string itself to display color?

Example

"this is a @rred@n word."

The word "red" would be in red here.

I like this much better than how I understand the code to work: "this is a %sred%s word.", CRED, etc....

The latter seems very clunky to me, especially with lots of color going on.

Am I missing anything? Is there a way around that method?

Thanks!

Please Log in or Create an account to join the conversation.

More
12 May 2017 14:42 #6725 by Vatiken
Replied by Vatiken on topic Color
Code:
/****************************************************************************** How do I use extended colour? ******************************************************************************/ The special character used to indicate the start of a colour sequence is '\t' (i.e., a tab, or ASCII character 9). This makes it easy to include in help files (as you can literally press the tab key) as well as strings (where you can use "\t" instead). However players can't send tabs (on most muds at least), so this stops them from sending colour codes to each other. The predefined colours are: n: no colour (switches colour off) r: dark red R: bright red g: dark green G: bright green b: dark blue B: bright blue y: dark yellow Y: bright yellow m: dark magenta M: bright magenta c: dark cyan C: bright cyan w: dark white W: bright white o: dark orange O: bright orange /* Vatiken Additions */ p: dark pink P: bright pink +: bold -: blink _: underline =: reverse *: The '@' Symbol 1: Primary Colour 2: Secondary Colour 3: Tertiary Colour So for example "This is \tOorange\tn." will colour the word "orange". You can add more colours by updating the switch statement in ProtocolOutput(), and if you're using your own colour code, it can use extended colours in the same way. It's also possible to explicitly specify an RGB value, by including a four character colour sequence within square brackets, eg: This is a \t[F010]very dark green foreground\tn. Or: This is a \t[B210]dark brown background\tn. The first character is either 'F' for foreground or 'B' for background. The next three characters are the RGB (red/green/blue) values, each of which must be a digit in the range 0 (very dark) to 5 (very light). Finally, it's also possible to retrieve the colour code directly by calling the ColourRGB() function. This uses a static buffer, so make sure you copy the result after each call, don't do a sprintf() with multiple ColourRGB() calls. Note that sending extended colours to a terminal that doesn't support them can have some very strange results. The snippet therefore automatically downgrades to the best-fit ANSI colour for users that don't support extended colours. Because there is no official way to detect support for extended colours, the snippet tries to work it out indirectly, erring on the side of caution. If the b256Support variable in the protocol structure is set to "eSOMETIMES", that means some versions of this client are known to support extended colour - you will need to ask the user, and then set eMSDP_XTERM_256_COLORS to 1 (or they can do this themselves through MSDP/ATCP).

ProtocolSystem.txt in the doc/ folder.

Beneath the snippet on adding colour is also the information required to add other features like clickable links and downloadable GUIs.

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

More
13 May 2017 00:44 #6727 by Parnassus
Replied by Parnassus on topic Color
The main problem that people find when using color codes in triggers is that the trigger was not told to enable the color codes. You can see the procedure in HELP TEXT-EDITOR.
Code:
help TEXT-EDITOR The text editor is what you use to write room/mob/obj/extra descriptions, mudmails, and even boards. It allows you more commands than the typical entry. To learn the commands while using the text editor, type /h. It will tell you what all the / commands do. Always use /fi to format, indent, and word wrap. It looks much better to see writing that is formatted than one that runs all over the place wrapping around etc. Just simply type /fi on a new line and hit enter. Before you save type /l to list the buffer and see for yourself how it looks. Fix as needed. When entering the text editor for the first time make sure to use /c to clear the current contents. Indent and format all descriptions by typing /fi (format with indent) in the text editor. This includes all forms of OLC, mudmails, boards, and anywhere else you use the text editor. This will indent the line by 3 spaces and wrap your text at less than 80 characters so telnet users can read it. Editor command formats: /<letter> /t - converts @ color codes into color. Use prior to /s. ...Information truncated here to save space but it's all interesting and helpful, really worth reading.... /s - saves the text and exits the editor. NOTE: /f and /fi in trigedit will auto indent your trigger. PLEASE USE IT. Warning: Some clients will give you problems since they use special characters like the / character (MUDMaster 2k, Avplay, Mush, and SimpleMU).

I'm not sure what Vatiken is using but these are the codes I use:
Code:
help COLORCODES Usage: If you have a color-capable terminal and wish to see useful color-coding of information, use PREFEDIT to set the level of coloring you see. The letters for the colors are to be preceded by a single @ sign, where the actual code will be @<letter>. @* = single @. All use of colorcodes MUST be terminated with @n to restore normal color to prevent color bleeding. ANSI colors: @n - normal @* - @ Other Codes @d - black @D - gray @1, @2, @3 MUD primary colors @b - blue @B - bright blue @- - blink @+ - bold @g - green @G - bright green @_ - underline @= - reverse video @c - cyan @C - bright cyan @r - red @R - bright red 256 Colors: @m - magenta @M - bright magenta @p - pink @P - bright pink @y - yellow @Y - bright yellow @o - orange @O - bright orange @w - white @W - bright white @[F###] - SHOW COLOUR to list all codes. See also: @, OLC-COLOR, MXP, ANSI, PROMPT, TOGGLE, SHOW-COLOUR

This may be because my client is so old that when I type SHOW COLOUR, most of the codes seem to be the same colors over and over.

Please Log in or Create an account to join the conversation.

Time to create page: 0.199 seconds