EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
[Script] [Util] Chem String Functions Library v. 2.97 [19-01-2009]
Post new topic Reply to topic Goto page 1, 2  Next
View previous topic :: View next topic
Author Message
ChemODun





Joined: 12 Feb 2007
Posts: 320 on topic
Location: Kyiv, Ukraine
Thank you for registering your game
PostPosted: Wed, 21. Jan 09, 23:20    Post subject: [Script] [Util] Chem String Functions Library v. 2.97 [19-01-2009] Reply with quote Print

################################################################################
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



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 -


Or if not:
output without 'fill.spaces'

output wtih 'fill.spaces'


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
Back to top
View user's profile Send private message Send e-mail
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Sun, 22. Mar 09, 21:11    Post subject: Reply with quote Print

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:
$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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
Tim-O





Joined: 15 Dec 2005
Posts: 182 on topic

Thank you for registering your game
PostPosted: Mon, 23. Mar 09, 00:10    Post subject: Reply with quote Print

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

Code:
Mode = 'fill.spaces'


Back to top
View user's profile Send private message
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Mon, 23. Mar 09, 20:18    Post subject: Reply with quote Print

First: Thanks/Danke Wink for the reply.

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

Code:
$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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
strude





Joined: 03 Aug 2005
Posts: 1435 on topic
Location: Adelaide, Australia
Thank you for registering your game
PostPosted: Tue, 24. Mar 09, 03:56    Post subject: Reply with quote Print

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 H77M-D3H | i7 3770 | 8Gb 1600 DDR3 | Gigabyte RadeonHD 7870 OC | Asus Xonar DGX | Window 10 Home 64bit | Samsung 256Gb SSD
Back to top
View user's profile Send private message
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Tue, 24. Mar 09, 15:07    Post subject: Reply with quote Print

Quote:
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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Wed, 25. Mar 09, 01:52    Post subject: Reply with quote Print

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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
ChemODun





Joined: 12 Feb 2007
Posts: 320 on topic
Location: Kyiv, Ukraine
Thank you for registering your game
PostPosted: Wed, 25. Mar 09, 13:58    Post subject: Reply with quote Print

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:
$ware = call script lib.chem.strings: Mode = 'fill.spaces' Arg1=$ware, Arg2=30, Arg3='-', Arg4=null, Arg5=null

as documented -
Quote:

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 Smile .


_________________
Multiply entropy by absolute zero

Ñâîáîäà ñðåäè çâåçä / Freedom in space
Back to top
View user's profile Send private message Send e-mail
strude





Joined: 03 Aug 2005
Posts: 1435 on topic
Location: Adelaide, Australia
Thank you for registering your game
PostPosted: Wed, 25. Mar 09, 14:03    Post subject: Reply with quote Print

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 H77M-D3H | i7 3770 | 8Gb 1600 DDR3 | Gigabyte RadeonHD 7870 OC | Asus Xonar DGX | Window 10 Home 64bit | Samsung 256Gb SSD
Back to top
View user's profile Send private message
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Fri, 17. Apr 09, 21:52    Post subject: Reply with quote Print

Hi,

it's me again. =)

The description says:

Quote:
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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
rothbard





Joined: 22 Oct 2008



PostPosted: Fri, 24. Apr 09, 19:52    Post subject: Reply with quote Print

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?

Back to top
View user's profile Send private message
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
PostPosted: Fri, 24. Apr 09, 20:05    Post subject: Reply with quote Print

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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht
Back to top
View user's profile Send private message
rothbard





Joined: 22 Oct 2008



PostPosted: Fri, 24. Apr 09, 20:23    Post subject: Reply with quote Print

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!

Back to top
View user's profile Send private message
draffutt



MEDAL

Joined: 21 Feb 2007
Posts: 3918 on topic

Thank you for registering your game
PostPosted: Sat, 25. Apr 09, 00:20    Post subject: Reply with quote Print

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
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ScRaT_GER





Joined: 08 Jan 2008
Posts: 1958 on topic

Thank you for registering your game
modified
PostPosted: Sat, 25. Apr 09, 12:43    Post subject: Reply with quote Print

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


_________________

Skripts:
Teladi Informations Service, Fahrtenbuch, Handelsübersicht


Last edited by ScRaT_GER on Sun, 26. Apr 09, 16:32; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic Reply to topic Goto page 1, 2  Next
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Fri, 15. Dec 17, 10:11

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.17384 seconds, sql queries = 29