[FIX] Blank Messages containing Colored Names (email from Klaus)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

[FIX] Blank Messages containing Colored Names (email from Klaus)

Post by h2o.Ava »

This should no longer be needed with the next X3TC update, version 3.1.

A Fix for Blank Messages containing Colored Names
I would like to propose a new standard.
Below is some code which makes it possible to send message, send question, and write to player logbook when an object has a colored name.



Why?

Color coding is very useful and ascetically pleasing. Following this new standard will benefit the community as a whole by opening up many new possibilities: ship organization, wing designation, hostile ships, abandoned ships, damaged ships, ships currently being boarded, etc.



The Proposal:

I propose that whenever anyone sends a message/question to their players, you add the proposed code immediately above all instances of send message, send question, or write to players logbook which send any objects name to the player. Wares, sectors, ships, etc. The extra work that it requires is only a few more lines of code and searching for "send message", "send question", and "write to player logbook".



[ external image ](.zip)



The Code:
Place above every send message, send question, and write to logbook using Exscriptor, '' [two apostrophes and a blank] cannot be input with the in-game SE. Please inform me of any other instances that this occurs.
Input: $name
Output: $name

append.to.your.code:

Code: Select all

* strip color
$escape.on = get global variable: name='color.escape.on'
if $escape.on != [TRUE] 
  send incoming message 'Color Escape Fix must be installed' to player: display it=[TRUE]
  set global variable: name='plugin.dynamic.c.s.n' value=null
  return null
end
$escape = get global variable: name='color.escape'
$find = find position of pattern $escape in $name
while $find > -1 
  $pattern = get substring of $name offset=$find length=2
  $name2 = substitute in string $name: pattern $pattern with ''
  $find = find position of pattern $escape in $name2
  $pattern = get substring of $name2 offset=$find length=2
  $name = substitute in string $name2: pattern $pattern with ''
  $find = find position of pattern $escape in $name
end

T file:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<language id="44">

<page id="7" title="Boardcomp. Sectornames" descr="Names of all sectors (spoken by Boardcomputer)" voice="yes">

<t id="1025002">A\033Bcquisition Repository\033X</t>

</page>
</language>
setup.script:

Code: Select all

load text: id=6874
$escape = get global variable: name='color.escape'
 
$name.orig = [PLAYERSHIP]->get name
 
$text = sprintf: pageid=7 textid=1025002, null, null, null, null, null
[PLAYERSHIP]->set name to $text
= wait 1000 ms
$name = [PLAYERSHIP]->get name
 
[PLAYERSHIP]->set name to $name.orig
 
$length = get length of string $name
$small = $length - 2 
$escape = get substring of $name offset=$small length=1
 
set global variable: name='color.escape' value=$escape
set global variable: name='color.escape.on' value=[TRUE]
 
return null
Last edited by h2o.Ava on Fri, 21. Jan 11, 01:29, edited 12 times in total.
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

I had an eureka moment while eating and now we have a code which pulls the color from anything.
All we need is to place the T file, setup script, and then append the code into your scripts above any send message/question/write to player logbook lines.

Thanks for reading and using it. Please feel free to throw apples and other fruit at me if I came across as anything undesirable. I really prefer Raspberries.


Opinions?
So far I have received the suggestion of making this into a library, cutting down the lines you would need to use and making the colors appear in the messages by converting them from \033R to [RED]. (Thank you Trickmov)

So far I know of the following colors, am I missing any?
\033A
\033B
\033C
\033G
\033M
\033O
\033V
\033R
\033W
\033Y

[BLUE]
[CYAN]
[GREEN]
[MAGENTA]
[RED]
[VIOLET]
[WHITE]
[YELLOW]
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

I could've sworn there was a .... /033x ? (default?) I may be imagining it (and I'm too tired to find out :( tis now 29 minutes into Christmas, and time to sleep)
User avatar
TECSG
Posts: 1610
Joined: Tue, 17. Feb 04, 22:06
x3tc

Post by TECSG »

Hi h2o.AvA,

If you check out my SCS scripts (here), there are routines to convert short colour format (like \033R) to long colour format (like [yellow]) and vice-versa or strip all colour codes entirely.

Your routines (like all others) will not help with messages from the game itself though, you will still get blank messages in the logbook. My SCS routines employ a work-round to alert you if a ship with a coloured name is destroyed as I got fed up having to check all my ships were still okay every time there was a blank message written in to the logbook.

Hope you find that useful.

@s9ilent,
The \033X code terminates the current colour code, text will then revert to the previous colour (or the 'default' green if no other colour codes are active).
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

Thanks, I'll look into it.

What messages come from the game itself, I don't know if I have seen any. :P
User avatar
TECSG
Posts: 1610
Joined: Tue, 17. Feb 04, 22:06
x3tc

Post by TECSG »

Hi h2o.AvA,

You can get messages from the ST/UT scripts (I think the 'ship was attacked' messages will do it) and the most common one I get is when trying to jump a ship that doesn't have enough Energy Cells. The game tries to write something like:

Message from [SHIP]

Insufficient Energy Cells to jump.


However, as usual, you just get a blank message if the name is coloured.

The 'blank messages in the logbook' has been a well documented problem since (practically) day one. I know Cycrow has had problems with this bug too and I've been requesting the devs fix it since V2.1 or so...
User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube »

UniTrader wrote a library, which is accesible on page two of this:

http://forum.egosoft.com/viewtopic.php?t=220124

I've been using it since day one, and it's solid.

As for the "ship destroyed", edit the default T file to disregard the %s ship variable. I've written my own subtitle alert for destroyed property, so I don't use the log for that.

There are !vanilla scripts that use writing to message log as well, UT scripts, patrol scripts, and the sudoko script. Easy enough to edit if you use exscriptor.
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

I wonder why they don't..
It seems to be a very simple fix, since we can strip out the coloring via SE.
User avatar
TECSG
Posts: 1610
Joined: Tue, 17. Feb 04, 22:06
x3tc

Post by TECSG »

That's what I thought several versions ago!

It should just be a simple matter of either stripping the colour codes or converting them to the other format, but I guess they had more important things to fix...

Still, here's hoping for V3.1!

:lol:
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

Want to code it for them and provide the code to them?
Then they wont need to spend near as much time on it. :wink:
User avatar
TECSG
Posts: 1610
Joined: Tue, 17. Feb 04, 22:06
x3tc

Post by TECSG »

I would think they already have the code to do it hardwired, given that the old code system was used in the BBS/sector maps and the new colour codes are XML based, however, all they have to do is ask!
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

@h2o.AvA

2 colors you don't have listed.

\033Z (Grey)
\033K (Black)

As found in the second posting here.


MarCon
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

Thank you Mark.
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

new version

slight code changes
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

Good news, this fix most likely will not be necessary in the future. I received the following from Klaus.

Hello,

thanks for your input. Using color escape codes in incoming messages cause an XML parser error, but this issue has not been fixed because we were under the impression that there are simple workarounds and alternatives. This is not true any more with respect to mods that add colors to object names.

I've looked into message parsing, and it's indeed an easy fix. If the tests look good it will be included in the next update, so the workaround scripts would not be needed any more. However, color tags should still be preferred when possible because they also work with word wrap.

HTH
-Klaus

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”