String lists are ordered collections of strings. Xelagot uses Delphi's TStringList objects for these. The contents can be saved to or loaded from file, and manipulated in various ways, as listed below in the Statements section. Specific use is to store name=value pairs, and as database. Xelagot 3.600 introduces a new way of handeling the string list as database, with statements starting with DB instead of SList.
These lists must first be declared using the var keyword, as
they are not created by default. See Xelagot action script: Variables. They
store strings.
For example, you can create string lists called /s_myList,
/s_myList1, /s_myList2:
var /s_myList, /s_myList1, /s_myList2 |
As from X1 2.9999975 and Av99bot/SrvcXlgBot 2.8 onwards, you can pack the name of a string list into a Packer variable, and use it as a substitute. This gives you a lot of flexibility when you need to apply the same operations to different string lists. For example:
var /s_myList1, /s_MyList2 # instead of # SListClear /s_MyList1 # SListClear /s_MyList2 # you can write ^a = "/s_MyList1" SListClear ^a ^a = "/s_MyList2" SListClear ^a |
Clearing, Retrieving, Loading, Saving:
/s_myList1 = /s_myList2 | clears list /s_myList1, copies all strings from /s_myList2 to /s_myList1. Does not work with string variables that contain string list names: in this case, use SListCopy (or 3.600 statement DBCopy). |
SListClear /s_myList | clears the list |
DBClear /s_myList | xelagot 3.600 clears the list. Note: this does exactly the same as SListClear, it does not check the validity of the database. It has been added for uniformity in the notation. |
SListLoad /s_myList $file [%rc] | loads a text file $file into the list. Optionally %rc
= 0 if all goes well, -1 otherwise. xelagot 3.607 or newer The filename convention is explained in the section Filenames. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
DBLoad /s_myList $file [%rc] | xelagot 3.600 loads a text file $file into the list. Optionally %rc = 0 if all goes well, -1 otherwise. After loading the file, it removes any line that is not a valid name=value pair. Note: this does almost exactly the same as SListLoad, it does not check the validity of the database but it removes any lines that do not have a name=value pair, i.e. it combines SListLoad and SListNameValueOnly. xelagot 3.607 or newer The filename convention is explained in the section Filenames. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
SListMerge /s_myList $file [%rc] | merges a text file $file into the list. Optionally %rc = 0 if all goes well, -1 otherwise. xelagot 3.607 or newer The filename convention is explained in the section Filenames. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
SListSave /s_myList $file [%rc] | saves a list as text file $file, overwriting the file if it
exists. Optionally %rc = 0 if all goes well,
-1 otherwise. xelagot 3.607 or newer The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
DBSave /s_myList $file [%rc] | xelagot 3.600 saves a list as text file $file, overwriting the file if it exists. Optionally %rc = 0 if all goes well, -1 otherwise. Note: this does exactly the same as SListSave, it does not check the validity of the database. It has been added for uniformity in the notation. xelagot 3.607 or newer The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
SListSaveAppend /s_myList $file [%rc] | x1 2.9999971 Appends a list to text
file $file (creates the file if it does not exist). Optionally %rc = 0 if all goes well,
-1 otherwise. xelagot 3.607 or newer The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file. xelagot 3.606 or older The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths. |
SListCopy /s_myList1 /s_myList2 | X1 2.9999977 Clears list /s_myList1, copies all strings from /s_myList2 to /s_myList1. Works also with string variables that contain string list names. |
DBCopy /s_myList1 /s_myList2 | xelagot 3.600 Clears list /s_myList1, copies all strings from /s_myList2 to /s_myList1. Works also with string variables that contain string list names. Note: this does exactly the same as SListCopy, it does not check the validity of the database. It has been added for uniformity in the notation. |
SListAppend /s_myList1 /s_myList2 | X1 2.9999977 Copies all strings from /s_myList2 to /s_myList1, appending them (it does not clear /s_MyList1 first). Works also with string variables that contain string list names. |
SListSetText /s_myList $t | clears the list and adds the text pointed at by text label $t |
SListAddText /s_myList $t | appends to the string list the text pointed at by text label $t |
SListNoBlanks /s_myList | removes all empty lines and lines which contain only blanks (spaces, tabs). |
SListNameValueOnly /s_myList | removes all entries from the list that are not a name=value pair |
SListTrim /s_myList | xelagot 3.608
removes all leading and trailing blanks (spaces, tabs) from lines in the string list. |
Manipulating individual entries:
x1 2.9999975 SListCount /s_myList %c older SListGetCount /s_myList %c |
retrieves the number of items in the list and stores that value in %c | ||
DBCount /s_myList %c |
xelagot 3.600 retrieves the number of items in the list and stores that value in %c. Note: this does exactly the same as SListCount, it does not check the validity of the database. It has been added for uniformity in the notation. |
||
x1 2.9999975 SListAdd /s_myList $t older SListAddLine /s_myList $t SItemAdd /s_myList $t |
appends to the string list the string $t | ||
x1 2.9999975 SListGet /s_myList [%p] $a older SItemGet /s_myList [%p] $a |
assigns to $a the string in item index %p of list, and resets the list pointer to %p. If %p is not specified, uses the current pointer value. | ||
x1 2.9999975 SListReplace /s_myList [%p] $a older SItemReplace /s_myList [%p] $a |
assigns to the item index %p the value of $a and resets the list pointer to %p. If %p is not specified, uses the current pointer value. | ||
x1 2.9999975 SListInsert /s_myList [%p] $a older SItemInsert /s_myList [%p] $a |
inserts a new item in the list at index %p, assigns it the value of $a and resets the list pointer to %p. If %p is not specified, uses the current pointer value. If the pointer is out of rande, adds an item to the list. | ||
x1 2.9999975 SListDelete /s_myList [%p] older SItemDelete /s_myList [%p] |
deletes item index %p. If %p is not specified, uses the current pointer value. | ||
x1 2.9xxx SListGetValue /s_myList $n $v SListGetValue /s_myList %n $v older SItemGetValue /s_myList $n $v SItemGetValue /s_myList %n $v |
Gets the value $v from the name $n in a name=value pair. The
name is not case sensitive. The string stored in the list must have
the following structure: name=value. If the name is an integer, the second convention %n may be followed. Note: if the list is database 'old style', the value retrieved corresponds to the entire comma separated record (except for the name field). xelagots 3.606 or newer can use SListRecordGetField and SListRecordGetFields to retrieve the individual fields from $v. |
||
DBGetValue /s_myList $n $v DBGetValue /s_myList %n $v |
xelagot 3.606 Gets the value $v from the name $n in a name=value pair (the $name gets DBEncoded automatically). The name is not case sensitive. The string stored in the list must have the following structure: name=value. If the name is an integer, the second convention %n may be followed. It is assumed that the list has a DB structure, but the only requirement is that it contains name=value pairs, and that names are DBEncoded. Note: if the list is database 'new style', the value retrieved corresponds to the entire comma separated record (except for the name field), DBEncoded fields remain DBEncoded. xelagots 3.606 or newer can use DBRecordGetField and DBRecordGetFields to retrieve the individual fields from $v. |
||
IfSListGetValue /s_myList $n $v
statement IfSListGetValue /s_myList %n $v statement |
similar to SListGetValue, combined with an IfString $v <> "" statement: if it gets a valid value ($v is not empty) executes statement. May be followed by an Else clause. | ||
IfDBGetValue /s_myList $n $v
statement IfDBGetValue /s_myList %n $v statement |
xelagot 3.600 A weird little statement for a database, mainly used to test whether a record with name $n or %n exists. The value retrieved is a comma separated list of DBEncoded fields. |
||
x1 2.9xxx SListSetValue /s_myList $n $v SListSetValue /s_myList %n $v older SItemSetValue /s_myList $n $v SItemSetValue /s_myList %n $v |
Sets the value $v from the name $n in a name=value pair. The
name is not case sensitive, and a value of an existing name=value
pair will be replaced by the new value. The string stored in the
list will have the following structure: name=value. If the name is an integer, the second convention %n may be followed. |
||
SListDeleteName /s_myList $n SListDeleteName /s_myList %n |
Removes, if the name=value pair is found, the name $n and its associated value from the list. If the name is an integer, the second convention %n may be followed. | ||
DBDeleteName /s_myList $n DBDeleteName /s_myList %n |
xelagot 3.600 First, converts the value $n using DBEncode, then removes, if the name=value pair is found, the name $n and its associated value from the list. If the name is an integer, the second convention %n may be followed. To be used on string list databases made with DBSetField(s), or when names are DBEncoded. |
||
SListGetNames /s_myList $a |
makes a comma separated formated string $a (ready for printing) of all names in name=value pairs. Returns an empty string if none found. | ||
DBGetNames /s_myList $a |
xelagot 3.600 makes a comma separated formated string $a (ready for printing) of all names in name=value pairs. Returns an empty string if none found. To be used on string list databases made with DBSetField(s), or when names are DBEncoded. |
||
SListGetNamesSDF /s_myList $a |
xelagot 3.606 makes a comma separated formated string $a (using the SDF method) of all names in name=value pairs. Returns an empty string if none found. Use GetFirstSDF $n $a repeatedly to recover the individual names in $n, until $n has an empty string. |
||
DBGetNamesSDF /s_myList $a |
xelagot 3.606 makes a comma separated formated string $a (using the SDF method) of all names in name=value pairs. Returns an empty string if none found. To be used on string list databases made with DBSetField(s), or when names are DBEncoded. Use GetFirstSDF $n $a repeatedly to recover the individual names in $n, until $n has an empty string. |
||
SListSetField /s_myList
$n %f %i SListSetField /s_myList $n %f !t SListSetField /s_myList $n %f @p SListSetField /s_myList $n %f &p SListSetField /s_myList $n %f ~p SListSetField /s_myList $n %f $a or SListSetField /s_myList %n %f %i SListSetField /s_myList %n %f !t SListSetField /s_myList %n %f @p SListSetField /s_myList %n %f &p SListSetField /s_myList %n %f ~p SListSetField /s_myList %n %f $a |
this statement is only used in lists containing name=value
pairs, where the value is a comma separated string containing
fields (no commas are allowed in these fields). The fields may
represent strings, integers, delphi-style DateTime floats, and
location optionally including world (also person and object as
location). SListSetField looks for name $n and creates it if
necessary. Then it searches for field number %f starting by 1,
creates empty fields when necessary. It then puts the value
represented by the last variable in its corresponding field. If the name is an
integer, the second convention %n may be followed.
Note: you can not store a float value directly from a numeric variable, you must first convert it to string (e.g from %a to $a) and then store the string: StringFromReal $a %a [%precision] |
||
DBSetField /s_myList
$n %f %i DBSetField /s_myList $n %f !t DBSetField /s_myList $n %f @p DBSetField /s_myList $n %f &p DBSetField /s_myList $n %f ~p DBSetField /s_myList $n %f $a or DBSetField /s_myList %n %f %i DBSetField /s_myList %n %f !t DBSetField /s_myList %n %f @p DBSetField /s_myList %n %f &p DBSetField /s_myList %n %f ~p DBSetField /s_myList %n %f $a |
xelagot 3.600 this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with SListSetField is that strings and the world name are encoded by DBSetField using DBEncode, that encodes percentage, comma and equal signs to %1, %2, %3. DBSetField looks for name $n and creates it if necessary. Then it searches for field number %f starting by 1, creates empty fields when necessary. It then puts the value represented by the last variable in its corresponding field. If the name is an integer, the second convention %n may be followed. Note: you can not store a float value directly from a numeric variable, you must first convert it to string (e.g from %a to $a) and then store the string: StringFromReal $a %a [%precision] |
||
SListGetField /s_myList $n %f %i SListGetField /s_myList $n %f !t SListGetField /s_myList $n %f @p SListGetField /s_myList $n %f &p SListGetField /s_myList $n %f ~p SListGetField /s_myList $n %f $a or SListGetField /s_myList %n %f %i SListGetField /s_myList %n %f !t SListGetField /s_myList %n %f @p SListGetField /s_myList %n %f &p SListGetField /s_myList %n %f ~p SListGetField /s_myList %n %f $a |
this statement is only used in lists containing name=value
pairs, where the value is a comma separated string containing
fields (no commas are allowed in these fields). The fields may
represent strings, integers, delphi-style DateTime floats, and
location optionally including world (also person and object as
location). SListGetField looks for name $n. Then it searches
for field number %f starting by 1, ignores non existing fields,
pretending they exist. It then retrieves the value represented by
the last variable in the field and assignes it to the variable.
Non-values or overflows default to: 0 for integers, the origin of
the Delphi DateTime system for date-time (30 dec 1899 0h 0m 0s), 0.000n 0.000w 0.00a 0.0
for location. If the name is an integer, the second convention %n
may be followed.
As from version 3.6, dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) As from version 3.6, floats can be read directly into numeric variables. Up to this version, you need to read into a string, e.g. $a, and then convert to numeric, using %a = $a. |
||
DBGetField /s_myList $n %f %i DBGetField /s_myList $n %f !t DBGetField /s_myList $n %f @p DBGetField /s_myList $n %f &p DBGetField /s_myList $n %f ~p DBGetField /s_myList $n %f $a or DBGetField /s_myList %n %f %i DBGetField /s_myList %n %f !t DBGetField /s_myList %n %f @p DBGetField /s_myList %n %f &p DBGetField /s_myList %n %f ~p DBGetField /s_myList %n %f $a |
xelagot 3.600 this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with SListGetField is that strings and the world name are decoded by DBGetField using DBDecode, that decodes commas, percentages and equal signs encoded by DBEncode, DBSetField and DBSetFields. DBGetField looks for name $n. Then it searches for field number %f starting by 1, ignores non existing fields, pretending they exist. It then retrieves the value represented by the last variable in the field and assignes it to the variable. Non-values or overflows default to: 0 for integers, the origin of the Delphi DateTime system for date-time (30 dec 1899 0h 0m 0s), 0.000n 0.000w 0.00a 0.0 for location. If the name is an integer, the second convention %n may be followed. Dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) Floats can be read directly into numeric variables. |
||
SListAddField /s_myList %f %i SListAddField /s_myList %f $a |
this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). SListAddField searches all name=value pairs for field number %f starting by 1, ignores non existing fields, pretending they are there. If the last parameter is a numeric variable, it then retrieves the integer value of the field and adds it up, the total sum of field number %f is assigned to %i. Non-integer values or overflows default to 0. If the last parameter is a string variable, it makes a comma separated formated string (ready for printing), similar to the one produced by SListGetNames. This statement has been renamed, it was first called SListAddFields, which now has another meaning. | ||
DBAddField /s_myList %f %i DbAddField /s_myList %f $a |
xelagot 3.600 this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with DBAddField is that strings by DBAddField using DBDecode, that decodes commas, percentages and equal signs encoded by DBEncode, DBSetField and DBSetFields. DBAddField searches all name=value pairs for field number %f starting by 1, ignores non existing fields, pretending they are there. If the last parameter is a numeric variable, it then retrieves the integer value of the field and adds it up, the total sum of field number %f is assigned to %i. Non-integer values or overflows default to 0. If the last parameter is a string variable, it makes a comma separated formated string (ready for printing), similar to the one produced by DBGetNames. |
||
SListSetFields /s_myList $n %c variables SListSetFields /s_myList %n %c variables |
this statement is only used in lists containing name=value
pairs, where the value is a comma separated string containing
fields (no commas are allowed in these fields). The fields may
represent strings, integers, delphi-style DateTime floats, and
location optionally including world (also person and object as
location). SListSetFields sets the first fields up to field
%c with the values provided in the variables. These variables must
be space-separated. To skip a field, use any non-variable
placeholder, like for instance a string-literal. For example: SListSetFields /s_TeamA $Paticipant 3 %hits xxx %total will set the 1st and 3rd fields of $Participant's record, and skip the second. The variables are the same as allowed for fields in SListSetField. If the name is an integer, the second convention %n may be followed. Note: you can not store a float value directly from a numeric variable, you must first convert it to string (e.g from %a to $a) and then store the string: StringFromReal $a %a [%precision] |
||
DBSetFields /s_myList $n %c variables DBSetFields /s_myList %n %c variables |
xelagot 3.600 this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with SListSetFields is that strings and the world name are encoded by DBSetFields using DBEncode, that encodes percentage, comma and equal signs to %1, %2, %3. DBSetFields sets the first fields up to field %c with the values provided in the variables. These variables must be space-separated. To skip a field, use any non-variable placeholder, like for instance a string-literal. For example: DBSetFields /s_TeamA $Paticipant 3 %hits xxx %total will set the 1st and 3rd fields of $Participant's record, and skip the second. The variables are the same as allowed for fields in SListSetField. If the name is an integer, the second convention %n may be followed. Note: you can not store a float value directly from a numeric variable, you must first convert it to string (e.g from %a to $a) and then store the string: StringFromReal $a %a [%precision] |
||
SListGetFields /s_myList $n %c variables SListGetFields /s_myList %n %c variables |
this statement is only used in lists containing name=value
pairs, where the value is a comma separated string containing
fields (no commas are allowed in these fields). The fields may
represent strings, integers, delphi-style DateTime floats, and
location optionally including world (also person and object as
location). SListGetFields gets the values in the first
fields up to field %c and assignes them to the variables. These
variables must be space-separated. To skip a field, use any
non-variable placeholder, like for instance a string-literal. For
example: SlistGetFields /s_TeamA $Paticipant 3 %hits xxx %total will retrieve the 1st and 3rd fields of $Participant's record, and skip the second. The variables are the same as allowed for fields in SListGetField. If the name is an integer, the second convention %n may be followed. As from version 3.6, dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) As from version 3.6, floats can be read directly into numeric variables. Up to this version, you need to read into a string, e.g. $a, and then convert to numeric, using %a = $a. |
||
DBGetFields /s_myList $n %c variables DBGetFields /s_myList %n %c variables |
xelagot 3.600 this statement is only used in lists containing name=value pairs, where the value is a comma separated string containing fields (no commas are allowed in these fields). The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with SListGetFields is that strings and the world name are decoded by DBGetFields using DBDecode, that decodes percentage, comma and equal signs encoded by DBEncode, DBSetField and DBSetFields. DBGetFields gets the values in the first fields up to field %c and assignes them to the variables. These variables must be space-separated. To skip a field, use any non-variable placeholder, like for instance a string-literal. For example: DBGetFields /s_TeamA $Paticipant 3 %hits xxx %total will retrieve the 1st and 3rd fields of $Participant's record, and skip the second. The variables are the same as allowed for fields in SListGetField. If the name is an integer, the second convention %n may be followed. Dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) Floats can be read directly into numeric variables. |
||
SListGetRecord /_myList %i $n variables | xelagot 3.600 This statement was added to xelagot 3.600 to help migrating old databases to the new DB style. Record number %i (from 1 to number of records obtained with SListCount %c) gets retrieved: the name field is assigned to $n, the other fields are assigned to the variable list, which is similar to the ones in SListGetFields. To migrate the database from old style in /s_old to /s_new, do something like this in a loop, where the name is retrieved in $citnumber, and there are 3 more fields, of which $citname is URLEncoded: SListGetRecord /s_old %i $citnumber $citname %life %shots URLDecode $citname $citname DBSetFields /s_new $citnumber 3 $citname %life %shots Note: If you need the whole value part of the name=value pair, use SListGetValue. |
||
DBGetRecord /_myList %i $n variables | xelagot 3.600 Similar to the previous statement but retrieves from new style database. May come in useful to retrieve a record by number. Do not use it to migrate databases! xelagot 3.606 Note: If you need the whole value part of the name=value pair, use DBGetValue. |
||
SListGetString /s_myList $n %c SListGetString /s_myList %n %c SListGetStringExact /s_myList $n %c SListGetStringExact /s_myList %n %c |
Matches $n with the whole strings in the list, and stops at the first occurrence of the string. Case insensitive or sensitive, but works faster if the match is exact. The notation with %n may be used if the list contains integers. If no match is found, %c = 0, otherwise %c is the item's index number (pointer, starts at 1). | ||
IfSListGetString /s_myList $n %c
statement IfSListGetString /s_myList %n %c statement IfSListGetStringExact /s_myList $n %c statement IfSListGetStringExact /s_myList %n %c statement |
similar to SListGetString and SListGetStringExact, combined with an IfInt %c > 0 statement: if it gets a valid value (%c > 0) executes statement. May be followed by an Else clause. Otherwise %c is the item's index number (pointer, starts at 1). | ||
IfSListInString /s_myList $a %frL %frS %posL %posS
$s statement IfSListInStringExact /s_myList $a %fr %pos $s statement see IfNameInString for an alternative statement
|
|||
IfSListWordInString /s_myList $a $w
statement IfSListWordInStringExact /s_myList $a $w statement see IfNameWordInString for an alternative statement
|
|||
IfSListGetNameValue /s_myList $a $n $v
statement |
used for lists that store name=value pairs. Checks all names (case insensitive) to see if one is equal to string $a. Retrieves the first match as $n (name) and $v (value). | ||
IfNameInString /s_myList $a $a1 $name $a2
$v statement IfSListNameInString /s_myList $a $a1 $name $a2 $v statement
|
|||
IfNameWordInString /s_myList $a $a1 $name $a2
$v statement IfSListNameWordInString /s_myList $a $a1 $name $a2 $v statement
|
|||
SListGetPointer /s_myList %c | retrieves the pointer to the current list item and stores that value in %c. A value of 0 means the list is empty. | ||
SListSetPointer /s_myList %c | sets the current list item and stores the pointer value in %c. If the pointer is set higher that the last item, or lower than 1, it will automatically be set to 1. If the list is empty, the pointer will default to 0. | ||
SListRenumber /s_MyList [NO] | xelagot 3.606 Prepends to each line in the list a number followed by an equal sign, starting with number 1. Optionally, can have a "NO" string parameter (literal or in a variable). If NO is omitted (default setting), it will, before prepending the number, look for an equal sign in the line and, if found, change it to a comma. See DBRenumber. | ||
DBRenumber /s_MyList [NO] | xelagot 3.606 Works exactly the same as SListRenumber. Usefull when having called an SQLQuerySelect statement, with %KeyField = -1, that only gives a comma separated record, with no name=value structure. Calling DBRenumber after this query adds the name part as a sequence of integers starting with 1, allowing you to use this /s_MyList as a database. The NO parameter may be omitted in this case, as it has no effect (equal signs are DBEncoded and do no show). | ||
SListRecordGetField $Record %Number %i SListRecordGetField $Record %Number !t SListRecordGetField $Record %Number @p SListRecordGetField $Record %Number &p SListRecordGetField $Record %Number ~p SListRecordGetField $Record %Number $a | xelagot 3.606 Assumes a comma separated list of field values in $Record, for example as retrieved from a database 'old style' with: SListGetValue /s_MyList $name $Record or with IfListGetValue etc. Retrieves an individual field at position %Number and stores it in the variable %i, !t, etc. Works similar to SListGetField, only the record is in a string instead of a list. | ||
DBRecordGetField $Record %Number %i DBRecordGetField $Record %Number !t DBRecordGetField $Record %Number @p DBRecordGetField $Record %Number &p DBRecordGetField $Record %Number ~p DBRecordGetField $Record %Number $a | xelagot 3.606 Assumes a comma separated list of field values in $Record, for example as retrieved from a database 'new style' with: DBGetValue /s_MyList $name $Record or with IfDBGetValue etc. Retrieves an individual field at position %Number and stores it in the variable %i, !t, etc, DBDecoding it if necessary. It works similar to DBGetField, only the record is in a string instead of a list. | ||
SListRecordGetFields $Record %Number variables | xelagot 3.606 $Record contains a comma separated string of fields values (no commas are allowed in these fields), as retrieved from a database 'old style' with: SListGetValue /s_MyList $name $Record or with IfListGetValue etc. It works similar to SListGetFields, only in this case the record is in a string instead of a list. The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). SListRecordGetFields gets the values in the first fields up to field %c and assignes them to the variables. These variables must be space-separated. To skip a field, use any non-variable placeholder, like for instance a string-literal. For example: SlistRecordGetFields $Scores 3 %hits xxx %total will retrieve the 1st and 3rd fields of the $Scores record, and skip the second. The variables are the same as allowed for fields in SListRecordGetField. Dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) Floats can be read directly into numeric variables. | ||
DBRecordGetFields $Record %Number variables | xelagot 3.606 $Record contains a comma separated string of DBEncoded field values, as retrieved from a database 'new style' with: DBGetValue /s_MyList $name $Record or with IfDBGetValue etc. It works similar to DBGetFields, only in this case the record is in a string instead of a list. The fields may represent strings, integers, delphi-style DateTime floats, and location optionally including world (also person and object as location). The difference with SListRecordGetFields is that strings and the world name are decoded by DBRecordGetFields using DBDecode, that decodes percentage, comma and equal signs encoded by DBEncode, DBSetField and DBSetFields. DBRecordGetFields gets the values in the first fields up to field %c and assignes them to the variables. These variables must be space-separated. To skip a field, use any non-variable placeholder, like for instance a string-literal. For example: DBRecordGetFields $Scores 3 %hits xxx %total will retrieve the 1st and 3rd fields of the $Scores record, and skip the second. The variables are the same as allowed for fields in DBRecordGetField. Dates and times stored in SQL format are also read correctly into a date time variable: YYYY-MM-DD hh:mm:ss YYYY-MM-DD (this one sets the time to 0h 0m 0s) hh:mm:ss (this one sets the date to 30 dec 1899) Floats can be read directly into numeric variables. | ||
Special statements. The sorting algorithm is QuickSort and is not 'stable' (successive sorts disarrange previous ones).
SListSortNames /s_myList SListReverseSortNames /s_myList SListSortField /s_myList %f SListReverseSortField /s_myList %f |
x1 2.9999977 Sorts the list according to names or field number %f in name=value pairs. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. |
SListSortUCNames /s_myList SListReverseSortUCNames /s_myList SListSortUCField /s_myList %f SListReverseSortUCField /s_myList %f |
x1 2.9999977 Sorts the list according to URLEncoded names or field number %f in name=value pairs. The requested name or field must contain only URL encoded strings. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. |
DBSortStringNames /s_myList DBReverseSortStringNames /s_myList DBSortStringField /s_myList %f DBReverseSortStringField /s_myList %f |
xelagot 3.600 Sorts the list according to DBEncoded names or field number %f in name=value pairs. The requested name or field must contain only DBEncoded strings. Databases made with the 3.600 DB prefix have all strings DBEncoded automatically. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. |
SListSortIntNames /s_myList SListReverseSortIntNames /s_myList SListSortIntField /s_myList %f SListReverseSortIntField /s_myList %f |
x1 2.9999977 Sorts the list according to integer names or field number %f in name=value pairs. The requested names or field must contain only integers. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. %f as -1 or -2 should only be used if the whole value or string is an integer. |
DBSortIntNames /s_myList DBReverseSortIntNames /s_myList DBSortIntField /s_myList %f DBReverseSortIntField /s_myList %f |
xelagot 3.600 Sorts the list according to integer names or field number %f in name=value pairs. The requested names or field must contain only integers. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. %f as -1 or -2 should only be used if the whole value or string is an integer. |
SListSortNumNames /s_myList SListReverseSortNumNames /s_myList SListSortNumField /s_myList %f SListReverseSortNumField /s_myList %f |
x1 2.9999977 Sorts the list according to numeric names or field number %f in name=value pairs. The requested names or field must be a number (integer or real), or a date-time value. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. %f as -1 or -2 should only be used if the whole value or string is numerical. |
DBSortNumNames /s_myList DBReverseSortNumNames /s_myList DBSortNumField /s_myList %f DBReverseSortNumField /s_myList %f |
xelagot 3.600 Sorts the list according to numeric names or field number %f in name=value pairs. The requested names or field must be a number (integer or real), or a date-time value. To sort by a field, %f must have the field number (1 or higher). If %f = 0, the names are sorted, if %f = -1 the values are sorted as one large field. And if %f = -2, then the whole string is used to sort the list. %f as -1 or -2 should only be used if the whole value or string is numerical. |
SListShuffle /s_myList | shuffles the items in the list in a random fashion. |
SayText %a [&p] /s_myList | sends the strings in the list to the chat buffer. Person variable &p is optional. See the section on Say for details. |
WhisperText %a &p /s_myList | sends the strings in the list to the whisper buffer. See the section on Say for details. |
Replace /s_myList1
/s_myList2 $c $d ReplaceInList /s_myList1 /s_myList2 $c $d |
Replace is a batch replacement statement, similar to its
string counterpart: it clears
/s_myList1, copies all strings from /s_myList2 to s_myList1,
replacing sub-string $c with string $d. Note that Replace
/s_myList /s_myList $c $d is also valid (that is, it will not
be cleared, substitutions are done in the list). X1 2.9999977 ReplaceInList has the same functionality as Replace, but admits string variables containing the names of string lists. It was introduced due to the ambiguity with the string counterpart of Replace. |
AttributesList /s_myList | dumps world attributes to a string list. See World attributes for details |
ChangeAttributes /s_myList | changes world attributes. See World attributes for details |
SListGetURLParams /s_myList $params | (xelagot 3.501) If the string $params contains parameters in the standard POST or GET method, they are set as name=value pairs in the string list (which is first cleared). All names and values are URLDecoded. |
In the following examples, I use $n or %n (integer) for name, and $v for value.
Put (or modify) a name=value pair in a string list:
Remove a name=value pair from a list:
List the names as a comma separated string in $a:
List the names as an SDF comma separated string in $a (xelagot 3.606):
use GetFirstSDF $n $a repeatedly to recover individual names in $n, until $n has an empty string. Get the value associated with a name:
You can also retrieve the exact 'spelling' of $n. In this case, test if $a is a name, retrieve it again in $n (with case preservation) and its value in $v
For parsing a string, for example string $a, there are a few statements associated with string list names. These can be used, for example, to parse chatlines: the script scans all names in the string list to see if one of them appears in string $a, either as a substring of $a or as a word in $a. Parsing $a for name as substring of $a: test if any of the names is a substring of $a. If this is the case, $a will be split into 3 parts: $a1 containing the part before the name, $n containing the name as spelled in $a, $a2 contains the rest of $a after the name. $v contains the value associated with $n
Parsing $a for name as word in $a: test if any of the names is a word of $a. Delimiters for words are: space and .,;:¡!¿?. If this is the case, $a will be split into 3 parts: $a1 containing the part before the name, $n containing the name as spelled in $a, $a2 contains the rest of $a after the name. $v contains the value associated with $n
(x1 2.9999977) To sort a list by names:
(x1 2.9999977) To sort by values, %f must be -1.
|
For a new and better way as from xelagot 3.600, see the next section. The methods described in this section remain valid, but new scripts should use the newer methods for xelagots 3.600 or higher. Databases created with the traditional method described here may be used with the new methods of next section only if fields (i) do not contain URLEncoded strings, (ii) do not contain the characters = or %. To migrate to a new style database, see the comments (first table) on SListGetRecord.
String lists can be used, in a limited way, as storage for database records. This is quite adequate, for example, to store scores in games and competitions. These lists can be made 'permanent' by saving them to file. Each name=value pair in a string list can be used as a database record. The name functions as the indexed field or primary key, other fields are comma separated entries in the value part of the name=value pair. You access each record individually using the name field and the number of another of its fields. Field numbers start by 1. You can access one or more fields in this way. Fields may not contain commas.
Create a record, or modify an existing one, by entering
a name ($n or %n) for the name field, and a field number %f (it may
be a literal) and a value $a for another of its fields:
You can modify more than one field at a time. %c is then the number of the last field to be modified (it may be a literal), 'variables' is a space separated list of variables of the type allowed in fields, starting by field number 1 up to the last field. To avoid modifying a field, just put an 'x' or any characters which are not a variable instead of a variable in the right position in this list.
SlistSetFields /s_ListA $n 3 $d x %i To retrieve values from fields, use SListGetField and SListGetFields:
A record can be retrieved by index (xelagot 3.600), this is handy to migrate databases to the new style:
Remove a record:
To totalise a numeric field at position %f, putting the total in %i, use:
To make a comma separated list in $a of all the strings in field number %f, use:
For a comma separated list of names im $a, use the old
(x1 2.9999977) To sort a list by names:
(x1 2.9999977) To sort by a field, %f must have the field number (0 for names, 1 or higher for fields).
|
Requires xelagot 3.600 or higher.
String lists can be used, in a limited way, as storage for database records. This is quite adequate, for example, to store scores in games and competitions. The traditional way is explained in the previous section. Xelagot 3.600 introduces a new way, in apearence very similar to the old way, but that automatically encodes and decodes string-data so as to avoid commas and equal signs; the encoding is done with the % character, so this character is also encoded: % to %1, comma to %2 and = to %3. These lists can be made 'permanent' by saving them to file. Each name=value pair in a string list can be used as a database record. The name functions as the indexed field or primary key, other fields are comma separated entries in the value part of the name=value pair. You access each record individually using the name field and the number of another of its fields. Field numbers start by 1. You can access one or more fields in this way. Fields may now contain commas and equal signs, as these get encoded, but it is better not to include commas in primary key fields (name in the name=value pair).
An enhancement introduced in xelagot 3.600 is the ability to communicate with SQL databases. Records retrieved from these databases are presented to xelagot as string lists, formatted according to this new encoding method, if a correct value is passed to the %KeyField parameter in SQLQuerySelect. For details on SQL connectivity, see Database Connectivity: SQL. NOTE: the name (key field) in the xelagot database is not case sensitive, in SQL databases it may be. Be aware of that when you build up your SQL database!
Databases created with these statements should not be used with the old traditional statements. Databases created with the old traditional statements can migrate to using the new statements described here only if their fields (i) do not contain URLEncoded strings, (ii) do not contain the characters % or =.
Create a record, or modify an existing one, by entering
a name ($n or %n) for the name field, and a field number %f (it may
be a literal) and a value $a for another of its fields:
You can modify more than one field at a time. %c is then the number of the last field to be modified (it may be a literal), 'variables' is a space separated list of variables of the type allowed in fields, starting by field number 1 up to the last field number %c. To avoid modifying a field, just put an 'x' or any characters which are not a variable instead of a variable in the right position in this list.
DBSetFields /s_ListA $n 3 $d x %i To retrieve values from fields, use DBGetField and DBGetFields:
A record can be retrieved by index (index starts at 1), $n will receive the name, the variables receive the other fields:
You can test if a record exists by name $n or %n, $v will receive a record, i.e. a comma separated list of DBEncoded fields (as from xelagot 3.600)
Or you can simply retrieve the record as in previous statement but without the conditional testing (xelagot 3.606)
This record $v can be used to retrieve the individual field values (xelagot 3.606)
similar to DBGetField and DBGetFields, only in this case the information is contained in a string and not a string list. Remove a record:
To totalise a numeric field at position %f, putting the total in %i, use:
To make a comma separated list in $a of all the strings in field number %f, use:
Caution: if a string field contains an encoded comma, it shows as comma in this string! If you do not want that, use the old SListAddField /s_MyList $a that will give you a comma separated list of DBEncoded items. You can then Split the string at commas, and use DBDecode to decode each item. See string operations. For a comma separated list of DBDecoded names in $a, you can also use:
SListGetNames /s_MyList $a that will give you a comma separated list of DBEncoded names. You can then Split the string at commas, and use DBDecode to decode each item. See string operations. For a SDF comma separated list of DBDecoded names in $a, you can also use (xelagot 3.606):
use GetFirstSDF $n $a repeatedly to recover individual names in $n, until $n has an empty string. To load from and save to file (filename $f), use:
To clear the database, to copy from database /s_myList2 to /s_myList1 (clearing /s_myList1 first), and to count the records, use:
If the database was retrieved from an SQL query and lacks a name field, i.e. is a pure DBEncoded comma separated list (e.g. when %KeyField = -1 in the query), a numeric name value followed by an equal sign can be prepended to each record, starting with 1 and ending with the number of records (xelagot 3.606)
To sort a list by names:
To sort by a field, %f must have the field number (0 for names, 1 or higher for fields).
|