[Script] [Util] Chem String Functions Library v. 2.97 [19-01-2009]

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

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

ChemODun
Posts: 320
Joined: Mon, 12. Feb 07, 22:58

[Script] [Util] Chem String Functions Library v. 2.97 [19-01-2009]

Post by ChemODun » Wed, 21. Jan 09, 23:20

################################################################################
Script : Chem String Functions Library
Author : Chem
E-mail : chemodun@gmail.com
Version: 2.97
Desc. :Provide some functions for manipulate with string, based on their displayed width
################################################################################

_____________
Download:
Spk version

Image

History :

2.97
-converted to X3:TC
_____________
Installation :

Install via Cycrow Script Manager (Plugin Manager)

_____________
Use:

Libraries has two script files:
setup.lib.chem.string.xml - this file prepare special array for filling string by space.
Script doesn't have any parameters.
lib.chem.strings.xml - main library script.
Script has 6 parameters:
mode (Work Mode) - for defining which function called from library
Arg1..Arg5 - for setting functions parameters
Now in version 2.81 library provide 8 functions:
1. split.string.by.delim
Arg1 - string-delimeter - string, or string from text file by page id Arg1 and text id Arg2
Arg2 - string-source - string, or string from text file by page id Arg2(or Arg3) and text id Arg3 (or $Arg4)
Arg3 - max count parts of source string (if null - max count = 99)
return - array of found parts of source string
It's function can split source string (first) by delimeter (second).
You can set maximum count of parts for splitting (Arg3), i.e. if source has more then one occurrence of delimiter , but you set Arg3 = 2 - function will return array with only 2 elements, first - source string before first occurrence of Arg1 in Arg2, and second - all source after this first occurrence.

2.'fill.spaces' - you can create string with correct displayed width in player logbook, i.e. after using this function on, for example, strings "this is long string" and "small string", they will be filled by spaces up to they width in pixels (not symbols) will be equal.
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- max len (in spaces, i.e. count of sybols " ")
Arg3 or Arg4- fill
if bool
TRUE - fill left (align right)
FALSE - fill right (align left)
if string
'-' - align left
'=' - align center
'+' - align right
It's function will fill source string by spaces based not on count of symbols in string, but on their summary width on screen in player logbook.
I.e. default length for one symbols it this function will taken equal to two spaces.
In fact some symbols have length more then two spaces, some - less.
Function use special array, was prepared in setup script by experimental data form text files x8910.xml.
Now supported only English, Russian, and German languages.
If length source string more then needed length - string will be truncated.
See examples:
If you browser support animated gif -
Image Image

Or if not:
output without 'fill.spaces'
ImageImage
output wtih 'fill.spaces'
ImageImage

3,4 'sum.to.string' and 'number.to.string'
Arg1 - integer
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)

5,6 'fill.sum.to.string' and 'fill.number.to.string'
Arg1 - integer
Arg2 - max length
Arg3 - TRUE - fill left (align right) or FALSE - fill right (align left)
return - string
will do convert number 1234567890 to string like 1,234,567,890 or
will do convert sum 1234567890 to string like 1,234,567,890 Cr (add default name of games currency)
Then fill converted string as it can be done via 'fill.spaces'
7 'sprintf'
Arg1 -
if string
- then format string
else if number
- page id for format string
Arg2
if Arg1 = page id
- then text id for format string
else if
- array - then array of params
else
- params
Arg3..Arg5 - params or array of params like Arg2

if param is string and has form (page;id) then it will be replaced with string from text file

Function works like sprintf function from ScE, but use unlimited count of params and extended syntax:

%[align][width]specifier
align:
- - left
= - center
+ - right (default)
width: needed width of string in pseudo symbols
specifier:
n - number
c - currency
s - string

8 'length'
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- - type of measurement units.
if [TRUE] - then result will be returned in spaces
otherwise - in pseudosymbols.
This function will return displayed length of source string.

_____________
Uninstallation:

Uninstall via Cycrow Script Manager (or Plugin Manager)


_____________
Languages:
Russian
English
Deutsch - thanks to Unitrader [KGB]

_____________
Info:
Uses
Text Files Used : 8910
Text Pages Used:8910
_____________


Edit: Added working xdownloads download link. X2-Illuminatus
Multiply entropy by absolute zero

Ñâîáîäà ñðåäè çâåçä / Freedom in space

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Sun, 22. Mar 09, 21:11

I just installed this library to use it in my script, but unfortunately it doesn't work. I only tried function 2 to fill a string with spaces.
I tried it as follows:

Code: Select all

$ware = call script lib.chem.strings: Mode = '2' Arg1=$ware, Arg2=30, Arg3='-', Arg4=null, Arg5=null
Unfortunately the retun value ($ware) is always null. What am I doing wrong?

Greets,
ScRaT

Tim-O
Posts: 182
Joined: Thu, 15. Dec 05, 23:02

Post by Tim-O » Mon, 23. Mar 09, 00:10

Don't use Mode = '2'
You have to use the name of the mode:

Code: Select all

Mode = 'fill.spaces'

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Mon, 23. Mar 09, 20:18

First: Thanks/Danke :wink: for the reply.

But I still get null as returnvalue.
I changed the call to:

Code: Select all

$ware = call script lib.chem.strings: Mode = 'fill.spaces' Arg1=$ware, Arg2=30, Arg3='-', Arg4=null, Arg5=null
For Arg2 I also tried other (higher) values, but no change...

Maybe I installed it incorrectly, because this is a pck-file. I tried to use the Plugin Manager (Beta 6), but it always crashes, when I try to switch to the right directory. So I unpacked the pck file and put the script and the t-file into the corresponding directories manually. Is there a problem with "installing" it this way?

If not, what could be the problem?

Greets,
ScRaT

strude
Posts: 1435
Joined: Wed, 3. Aug 05, 08:15

Post by strude » Tue, 24. Mar 09, 03:56

Only thing I could suggest is assign the $ware to a different variable before feeding it into the fill.spaces function. I'm assuming that $ware is a variable containing a ware reference, which could be confusing the function which is expecting a straight string? I also use this function and have not had a problem with it at all. Maybe try changing the return value to a new variable and see if that helps, even though I know it works when the return variable and the arg1 variable are the same.

Failing that, I'd make a copy of the script and edit it to throw out some debug info, to find out how the values are proceeding through the script and where they are getting lost
Gaming PC: Gigabyte H270M-D3H | i7 7700 | 16Gb DDR4 | Gigabyte GTX1060 6Gb OC | Asus Xonar DGX | Window 10 Home 64bit | Samsung 256Gb SSD

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Tue, 24. Mar 09, 15:07

Only thing I could suggest is assign the $ware to a different variable before feeding it into the fill.spaces function.

That was the solution, thanks.

Now I can use this library in my scripts!

Greets,
ScRaT

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Wed, 25. Mar 09, 01:52

I don't know if Chem plans any updates or so, however Tim-O modified the german t-file, to make it work better.
After I worked a bit with it, I discovered that Chem seems to have forgotten the letter "Q". So I added it to the german t-file.

You can get that t-file here: 8910-L049.xml.

This file is of course only interesting for german users. =)

Maybe some english user will improve the english t-file aswell.

Greets,
ScRaT

ChemODun
Posts: 320
Joined: Mon, 12. Feb 07, 22:58

Post by ChemODun » Wed, 25. Mar 09, 13:58

Thanks for using my script.

About German t-file - thanks ScRaT_GER for support, I will add it to next release.

About problem with

Code: Select all

$ware = call script lib.chem.strings: Mode = 'fill.spaces' Arg1=$ware, Arg2=30, Arg3='-', Arg4=null, Arg5=null
as documented -
2.'fill.spaces' - you can create string with correct displayed width in player logbook, i.e. after using this function on, for example, strings "this is long string" and "small string", they will be filled by spaces up to they width in pixels (not symbols) will be equal.
Arg1 - source string, or string from text file by page id Arg1 and text id Arg2
Arg2 or Arg3- max len (in spaces, i.e. count of sybols " ")
Arg3 or Arg4- fill
But I will add functionality to use any another type of value, not only strings.

P.S. My English not good, if someone can help me with documentation - it will be great.
P.P.S. I am now "young father", so I don't have enough time not only for scripts but and fir sleep too :-) .
Multiply entropy by absolute zero

Ñâîáîäà ñðåäè çâåçä / Freedom in space

strude
Posts: 1435
Joined: Wed, 3. Aug 05, 08:15

Post by strude » Wed, 25. Mar 09, 14:03

I think many people treat a long of the variable types as strings, since they generally return strings in use, but don't realise they are actually all different types. If you edit the functions to assign the passed argument to a new variable that would probably be sufficient for most cases I would think.
Gaming PC: Gigabyte H270M-D3H | i7 7700 | 16Gb DDR4 | Gigabyte GTX1060 6Gb OC | Asus Xonar DGX | Window 10 Home 64bit | Samsung 256Gb SSD

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Fri, 17. Apr 09, 21:52

Hi,

it's me again. =)

The description says:
If length source string more then needed length - string will be truncated.
Strange effects can be observed when using coloured texts and strings which are longer, than the desired lenght.

The coloured text also 'colours' the following texts.

For example if you want to display a text like this:

Your Ship with a super long name       Flighttime: ...

and the Ships name is even longer (might happen), the following happens:

Your Ship with an even longer super l Flightime: ...

See what I'm trying to say?

It would be great if you could review this function, if you find the time.
Maybe add a "." at the end of the shortened string, so that it is clear, that it was shortened.

Greets,
ScRaT

rothbard
Posts: 12
Joined: Wed, 22. Oct 08, 06:57

Post by rothbard » Fri, 24. Apr 09, 19:52

Does this script also function correctly when aligning strings for use is custom menus? I am getting some very subtle alignment errors (as in off 1 or 2 spaces) when doing a multicolumn layout for a large custom menu.

In the readme for this script there is mention of maximum display width of 100. From what I can tell the max width on the large menu is 142 or 143 (Varies depending on string, which I think is what leads to alignment issues). Would this mess up the padding functions of the script?

EDIT: Don't have a pic of my menu, but you can see exactly what I am talking about in ScRaT's thread http://forum.egosoft.com/viewtopic.php?t=243204. See how the columns don't quite line up?

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Fri, 24. Apr 09, 20:05

Well, slight aligninging "errors" occur, if you are using a character, which does not exactly match its assigned size.

In the German t-file, for example, the letter "q" was missing. So I added it, which enhanced the alignment in some cases.

As you are mentioning my thread: I think it's okay and way better than without the alignment.

Maybe you can observe which strings are the ones that pop out the most and find their difference to the others. Like this I found the missing letter "q" (which is btw still missing in the English t-file afaik).

Greets,
ScRaT

rothbard
Posts: 12
Joined: Wed, 22. Oct 08, 06:57

Post by rothbard » Fri, 24. Apr 09, 20:23

ScRaT_GER wrote:As you are mentioning my thread: I think it's okay and way better than without the alignment.
I agree that the alignment, even with small 'errors', is far superior to no alignment all. I just wanted to check and see if the small misalignments are the expected behavior, or 'operator error'. I will fiddle with the text file and see what I can come up with.

Nice work by the way on your trade overview script ScRaT. Looks really good. May have to add that one to my collection!

draffutt
Posts: 4250
Joined: Wed, 21. Feb 07, 18:46

Post by draffutt » Sat, 25. Apr 09, 00:20

i've added the missing "Q" and "q" to the english version.

8910-L044.xml

all other letters are there

@ScRaT_GER

i noticed in the file you posted here that it doesn't contain a lower case "q" is that intented?
None of us is as smart as all of us. ~Ken Blanchard

TC player bug fixes
Reunion player bug fixes

User avatar
ScRaT_GER
Posts: 1958
Joined: Tue, 8. Jan 08, 19:19

Post by ScRaT_GER » Sat, 25. Apr 09, 12:43

No, it's not.
I simply forgot to check it, because I didn't notice alignment error in strings containing a lower case "q".

I'll check which changes can be made to make better.

Greets,
ScRaT
Last edited by ScRaT_GER on Sun, 26. Apr 09, 16:32, edited 1 time in total.

Post Reply

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