[Library] positional format

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

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

Gqqnbig
Posts: 66
Joined: Fri, 12. Jul 13, 14:08

[Library] positional format

Post by Gqqnbig »

This package consists of a single function "positional format", which is like C#/.NET's "string.Format", taking a string with indexed tags and a number of parameters.

Concept and Example
Here is an example, using pseudo code.

Code: Select all

$message1 = sprintf: fmt='%s attacks %s', $attacker, [playership], null, null, null
$message2=  null-> call script 'positional format' :fmt='{0} attacks {1}', obj0=$attacker, obj1=[playership], obj2=null, obj3=null, obj4=null
both return 'Pirate Nova attacks Your Eclipse'. Note that fmt of positional format uses {n} symbol, where n starts from 0 and currently up to 4.

Now if we want to change the message to passive voice, we have to modify the code to the following.

Code: Select all

$message1 = sprintf: fmt='%s is attacked by %s', [playership], $attacker, null, null, null
$message2=  null-> call script 'positional format' :fmt='{1} is attacked by {1}', obj0=$attacker, obj1=[playership], obj2=null, obj3=null, obj4=null
Note that if we use the standard sprintf, we have to change both the string and the order of parameters ($attacker, [playership] to [playership], $attacker). But if using 'positional format', we don't have to change parameters.

The arguments of 'positional format' are actually

•0: pageid , Number , 'pageid'
•1: textid , Number , 'textid'
•2: obj0 , Value , '{0}'
•3: obj1 , Value , '{1}'
•4: obj2 , Value , '{2}'
•5: obj3 , Value , '{3}'
•6: obj4 , Value , '{4}'

Making use of positional format will greatly contribute to the globlization and localization of scripts. You should use 'positional format' to read and format external text files.

Different locales have varied language habit. If English likes passive voice, Chinese like positive voice. If a translator translates a script written in English to Chinses and if the author uses 'positional format', the translator doesn't have to modify the source code of the script, or use non-native sentence to suit the order of arguments.

Download
version: 0 experimental, 2013-08-28
author: gqqnbig
Compatibility: compatible to X3R. Others are not tested.

Download (SPK):Box.com, Dropbox

Install:
Install X-Universe Plugin Manager Lite first,then double click positioal format-V0-28.8.2013.spk.

Uninstall or Disable:
Use X-Universe Plugin Manager Lite to uninstall or disable.

Feedbacks are welcomed, of both introduction of the package and technical issues. Feel free if you have any question and don't hesitate to tell me if there is a duplicate library.

I'm developing some scripts that use this libray and should release soon.

Technical supports end on Februaray 1st, 2014.

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