[Script] [Util] Chem String Functions Library v. 2.81 [18 Aug 2007]

The place to discuss scripting and game modifications for X³: Reunion.

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

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

[Script] [Util] Chem String Functions Library v. 2.81 [18 Aug 2007]

Post by ChemODun » Mon, 26. Mar 07, 17:13

################################################################################
Script : Chem String Functions Library
Author : Chem
E-mail : chemodun@gmail.com
Web : http://www[dot]elite-games[dot]ru/x3/
Version: 2.81
Desc. :Provide some functions for manipulate with string,
based on their displayed width
################################################################################

_____________
Download:
Spk version
Zip version


History :

2.81
-added new function 'length', it return displayed width of string. If second parameter are [TRUE] - then length will be returned in spaces, otherwise - in pseudosymbols
2.78
-fixed error in functions 'fill.spaces', if used possibility read string from file - it's work incorrectly (Big thanks to X-Freak Cartman [KBG])
-used new version of .spk
2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)
2.75
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
- if string are longer then must be displayet - it's truncated
2.09 - first public release

_____________
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
_____________
Last edited by ChemODun on Sat, 18. Aug 07, 22:27, edited 14 times in total.
Multiply entropy by absolute zero

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

jgrg1
Posts: 9
Joined: Sun, 3. Aug 03, 17:13

Post by jgrg1 » Mon, 30. Jul 07, 00:36

Does anyone have a working link to this script? The one in the post doesn't seem to work.

Regards
Justin

sphr
Posts: 119
Joined: Tue, 15. Aug 06, 17:16
x4

Post by sphr » Mon, 30. Jul 07, 06:01

Is Chem still around and interested in maintaining the lib?
If not, I was thinking it would be possible to get permission to continue to maintain this lib as a part in the Common Library that I proposed much earlier.

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

Post by ChemODun » Mon, 30. Jul 07, 08:02

sphr wrote:Is Chem still around and interested in maintaining the lib?
If not, I was thinking it would be possible to get permission to continue to maintain this lib as a part in the Common Library that I proposed much earlier.
still :-)

Sorry, host was down.
Now hosten on Xai Corp - great host ;-)
thanks Moggy!
Multiply entropy by absolute zero

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

jgrg1
Posts: 9
Joined: Sun, 3. Aug 03, 17:13

Post by jgrg1 » Mon, 30. Jul 07, 10:57

Fantasico! Cheers.

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

Post by ChemODun » Mon, 30. Jul 07, 12:23

When I finish writing readme - you can use new function:
All old are still exists, for backward compability.
new wrote: sprintf - like standart in ScE, but with new format:
%[align][width]specifier
align:
- - left
= - center
+ - right (default)
width:
needed width of string in pseudo symbols
specifier:
n - number
c - currency
s - string
compability with first release wrote: sum.to.string
number.to.string
fill.spaces
fill.sum.to.string
fill.number.to.string
updated wrote: split.string.by.delim - now work wtih two bytes symbols (like russian). Additionally it will have short name split
Multiply entropy by absolute zero

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

User avatar
X-Freak Cartman
Posts: 3586
Joined: Mon, 2. Oct 06, 15:08
x3

Post by X-Freak Cartman » Fri, 3. Aug 07, 16:28

Hmm... Seems, as if the readme's a bit wrong:
'fill.spaces': Arg3 [TRUE]->right, [FALSE]->left.

The code says, that -1 means left.

I wondered why it didn't work ^^
Image
MSCI Referenz
Inaktiv

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

Post by ChemODun » Fri, 3. Aug 07, 18:48

New version - 2.75
- fixed error in definition aligining in functions 'fill.spaces', 'fill.sum.to.string', 'fill.number.to.string'
- added new function 'sprintf'
- functions 'fill.spaces', 'sprintf', 'split.string.by.delim' can use as parameters string, and integer vaules( for reading strings from text files)
- all functions corretly work with 2 bytes symbols (like Russian)
Multiply entropy by absolute zero

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

User avatar
X-Freak Cartman
Posts: 3586
Joined: Mon, 2. Oct 06, 15:08
x3

Post by X-Freak Cartman » Fri, 3. Aug 07, 22:48

ChemODun wrote:all functions corretly work with 2 bytes symbols (like Russian)
Hmm... either you changed the function of 'fill.spaces' to 'simply add spaces' or the sentence above is a bit wrong.

Seems as if your script simply adds spaces if I use the same arguments i used for version 2.09... Afaik, it should be compatible, shouldn't it?

I'll try to find an error in your code, but now, the new version is useless to me...

btw: Arguments
mode: 'fill.spaces'
Arg1: 'Testtext'
Arg2: 1, 2, 3, 5, 10, 20 and 30.
Arg3: 1, TRUE, -1

In version 2.09, the first five Arg3's had the same effect, now the number of spaces seems to simply be added.
Image
MSCI Referenz
Inaktiv

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

Post by ChemODun » Sat, 4. Aug 07, 00:40

Thanks, fixed for Arg3 = [FALSE] (must be fill right, i.e align left).

2.76
-fixed error with aligning in functions 'fill.spaces', where aling = [FALSE] (Was - filled left, but must be - filled right)

But I don't understand, what wrong?

I was check with

Code: Select all

001   load text: id=8910
002   $out = ' '
003   $arg1 = 'Testtext'
004   $arg2 =  array alloc: size=0
005   append 1 to array $arg2
006   append 2 to array $arg2
007   append 3 to array $arg2
008   append 5 to array $arg2
009   append 10 to array $arg2
010   append 20 to array $arg2
011   append 30 to array $arg2
012   $arg3 =  array alloc: size=0
013   append 1 to array $arg3
014   append [TRUE] to array $arg3
015   append -1 to array $arg3
016   append [FALSE] to array $arg3
017   
018   $arg3.l =  size of array $arg3
019   while $arg3.l
020     dec $arg3.l = 
021     $arg3.c = $arg3[$arg3.l]
022     $arg2.l =  size of array $arg2
023     while $arg2.l
024       dec $arg2.l = 
025       $arg2.c = $arg2[$arg2.l]
026 @     $result = [THIS] -> call script 'lib.chem.strings' :  Work Mode='fill.spaces'  Arg1=$arg1  Arg2=$arg2.c  Arg3=$arg3.c  Arg4=null  Arg5=null
027       $result = sprintf: fmt='|%s| arg2=%s, arg3=%s', $result, $arg2.c, $arg3.c, null, null
028       $out = sprintf: pageid=8910 textid=1098, $out, $result, null, null, null
029     end
030   end
031   write to player logbook $out
032   return null
Image
Image
Image

Or I want don't truncate string, if it more long, then Arg3 ?
Multiply entropy by absolute zero

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

User avatar
X-Freak Cartman
Posts: 3586
Joined: Mon, 2. Oct 06, 15:08
x3

Post by X-Freak Cartman » Sat, 4. Aug 07, 04:31

Great, this version fixed it.

Thxalot for this script. It's awesome.
Image
MSCI Referenz
Inaktiv

User avatar
X-Freak Cartman
Posts: 3586
Joined: Mon, 2. Oct 06, 15:08
x3

Post by X-Freak Cartman » Fri, 17. Aug 07, 16:12

What about a new version 2.77?

I could offer a Download. 2.76 has a major problem I recognised while using it for GAIUS:

Code: Select all

087     end
089     $source = $Arg1
090     $out.len = $Arg2
091     skip if not $debug
Whatever $Arg.String has been defined as in the read-text-subsection of the script, it always used Arg1 as source and Arg2 as length.

Well, there's an easy fix for that:

Code: Select all

087     end
088     $source = $Arg.String
089     skip if not $debug
That's all. It works properly and is ready for Download.

btw: You're allowed to use my server as a mirror. Just send me a PN and/or e-mail if you're releasing a new version and I'll upload it.

Edit: Links removed
Last edited by X-Freak Cartman on Sat, 18. Aug 07, 12:27, edited 1 time in total.
Image
MSCI Referenz
Inaktiv

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

Post by ChemODun » Fri, 17. Aug 07, 16:24

Many thanks.
Sure I will check it tomorrow.
Multiply entropy by absolute zero

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

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

Post by ChemODun » Sat, 18. Aug 07, 01:38

Thanks,
You can delete and string
088 $source = $Arg.String
I was delete this , test with debug - all works fine.

Thanks.
New version - are 2.78
Multiply entropy by absolute zero

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

User avatar
X-Freak Cartman
Posts: 3586
Joined: Mon, 2. Oct 06, 15:08
x3

Post by X-Freak Cartman » Sat, 18. Aug 07, 12:25

so... why don't you change the thread's name? :D

Edit: Much better now ^^
Image
MSCI Referenz
Inaktiv

Post Reply

Return to “X³: Reunion - Scripts and Modding”