Hpl2:Resources:script modules:stringlist

From Frictional Wiki
Jump to navigation Jump to search

String List

The StringList module provides a basic List data structure implementation, in a way which will not leak variables, and is non-volatile when saving (I.e. saved when the game is).


Downloads

Stripped (Reccommended) - A compact version with minimal documentation (just section headers). [1]] - A version with all documentation included in the source file. Assumes use of [Apjjm's Improved Notepad++ HPS Support

Installation

Copy and paste the desired script into your script file. OR save the script as an internal file and use an "#include filename.ext" with a Pre-Processer.

List Management

bool stringListCreate(string &in asName)


Creates a stringList with the given name. Returns true if the list was created successfully (no other lists with the same name).


bool stringListDestroy(string &in asName)


Destroys the list. Note that there will still be one or two empty string variables left after calling this, so creating multiple lists still leaks. Returns true if the destruction was successful (list existed).


bool stringListExists(string &in asName)


Returns true if the named list exists


int stringListSize(string &in asName)


Returns the size of the named list (0 if list is empty or does not exist)


void stringListClear(string &in asName)


Clears all elements from the list


Item Management

string[] stringListItems(string &in asName)


Returns all items in the named list as a string array. Use this if you wish to acess multiple elements in a list without changing the list.


int stringListAddItem(string &in asName, string &in asItem)


Adds asItem to the end of the named list. Returns the index of the item added (starting at 0). Returns -1 if the list doesn't exist.


void stringListAddItems(string &in asName, string[] asItems)


Adds the collection asItems to the end of named list.


string stringListGetItem(string &in asName, int alIndex)


Gets the item at the given index (alIndex) in the named list. For more than one item acess use array access & stringListItems(asName).


int stringListGetLastIndexof(string &in asName, string &in asItem)


Gets the index of the last occurance of asItem in the named list. -1 is returned if the item is not in the list (or the list does not exist)


int stringListGetFirstIndexof(string &in asName, string &in asItem)


Gets the index of the first occurance of asItem in the named list. -1 is returned if the item is not in the list (or the list does not exist)


bool stringListContains(string &in asName, string &in asItem)


Returns true if the list (provided it exists) contains a specific item.


bool stringListRemoveItemAt(string &in asName, uint alIndex)


Remove the item at the given index from the specified list. Returns true if an item was removed.


int stringListRemoveItems(string &in asName, string asItem)


Removes all items from the given list with the specified name. Returns 0 if no items match or the list does not exist. To remove a single item from the list combine stringListRemoveItemAt and stringListGetFirstIndexof


Constants

You may need to change the constants below if you wish to alter the list delimeter or the prefix of the list variable names.


const string _STRLPFX = "_!strli!_"; //Prefixed to all stringList var names - Change this if you get a naming conflict
const string _STRLDLM = "\0";    //SINGLE CHARACTER Delimiter for items in the list. This character may not be used in any item strings.