MQ2Collections

From the wonderful RedGuides Wiki
MQ2Collections
Collection types for MQ2 -- useful for scripts to create stacks, queues, maps, lists.
View details
Authors TypePun
Software type Plugin


Maintained Yes without support
Links

🏠Resource (review)
🥤Quick start •🤝Support •🛠️Repository

MQ2Collections is a Macroquest (MQ2) plugin. The plugin creates a number of collection types for MQ2 scripts. Out of the box MQ2 supports one collection: the array. Collection types enable script writers to use data structures that more naturally pair with the algorithm they are implementing. For example, if a script writer is implementing a first-in first-out structure for casting buffs, then a queue would be an appropriate structure. On the other hand, if he or she is maintaining a set of IDs representing mobs pulled to camp, then a set or list would be the natural mechanism.

Why did I write it?

My motivation in writing this plugin was to expose more powerful and natural data structuring tools to script writers. With these tools, script writers will be able to express solutions that solve the problem they want to solve rather than organizing data and building data structures.

What types are available?

The current release makes available the following data structures: the stack, set, list, queue and map. Iterators over the set, list and map are also provided. For those familiar with the C++ Standard Template Library (STL), the types and their semantics should seem natural. If they do not, please let me know by email at: [email protected].

Limitations

At present, the collections hold strings. That is, if you want to store an integer, floating point value or an object, you have to first convert it (or serialize it) as a string.

Official Documentation

Extensive documentation and manuals can be found here: https://github.com/TypePun/MQ2Collections/wiki


Commands

See also


Top-Level Object(s)

TLOs added by MQ2Collections:

TLO Data Type(s) Description
list list Holds the "list" datatype
listiterator listiterator Holds the "listiterator" datatype
map map Holds the "map" datatype
mapiterator mapiterator Holds the mapiterator datatype
queue queue Holds the "queue" datatype
set set Holds the "set" datatype
setiterator setiterator Holds the "setiterator" datatype
stack stack Holds the "stack" datatype

Members. More may be available if inherited. Typical usage, /echo ${TLO.Member}

TLO Data Type Return Type Member Description
list list bool Append[sequence] Insert a sequence of comma delimited strings onto the tail of the list.
Clear Removes all elements from the list. Always returns true.
Contains[string] True if at least one instance of string is contained in the list and false otherwise.
Erase[int] Remove an item from the input list by position. Return true if the item was removed or false if not.
Insert[int,sequence] Insert a sequence of comma delimited strings into the source list before the ordinal indicated by Integer. True is returned if the sequence could be inserted and false otherwise.
Reverse Reorder the list in such a way that the 0'th item is swapped with the Count -1th item, the item with ordinal 1 with the Count -2th item, etc.
Sort Lexicographically orders the items. The source list is modified in place.
int Count Number of items in the list.
CountOf[string] Return a count of the number of times string occurs in the list.
Index[string] Returns the ordinal position of String in the List or -1 if String can not be found.
Remove[string] Remove string from the input list. Return a count of how many times the item was removed.
Replace[string,string] Replaces the first string with the second string in the input list. A count of the number of times the replacement was performed is returned.
list Splice Returns a copy of the original list.
Splice[int, int] Returns a copy of the original list from the position specified by the first argument for an indicated number of elements.
Splice[int] Returns a copy of the original list from the indicated position to the end of the list.
listiterator Find[string] A listiterator is returned on the list where the current element under the iterator is the first item with a value equal to string if string is in the list and an empty iterator if it is not.
First A listlterator is returned on the list where the current element under the iterator is the Head of the list if the list has elements or an empty iterator if the list is empty.
string Delimiter[string] Sets the delimiter used to separate items in Insert and Append method calls. The previous delimiter is returned.
Head Remove and return the current item described at position 0 in the list. False is returned if the list is empty.
Item[int] Returns the string at the indicated position in the list.
Tail Remove and return the current item described by position Count -1 in the list. False is returned if the list is empty.
listiterator listiterator bool Advance The iterator is moved to the next item in the list, if one exists. True is returned if the iterator was advanced and False otherwise.
IsEnd True if the iterator is at the end of the list.
Reset Positions the iterator to the start of the list. True is always returned.
listiterator Clone Returns a copy of the current listiterator. A copy has independent life and initially is over the same element as the source iterator.
string Value Returns the element of the list under the iterator.
map map bool Add[string,string] True is returned if the item was added to the map. If the first string, called the 'key' is already in the map, the second string, called the 'value' will be replaced.
Clear Removes all items from the map. True is always returned.
Contains[string] True is returned if the item is in the map.
Remove[string] True is returned if the 'key' matching string was removed from the map.
int Count Number of items added to the map.
mapiterator Find[string] A mapiterator is returned on the map where the current element under the iterator is the item if the item is in the map and an empty iterator if it is not.
First A mapiterator is returned on the map where the current element under the iterator is the first element in the map if the map has elements or an empty iterator if the map is empty.
mapiterator mapiterator bool Advance The iterator is moved to the next item in the map, if one exists. True is returned if the iterator was advanced and False otherwise.
IsEnd True if the iterator is at the end of the map.
Reset Positions the iterator to the start of the map. True is always returned.
mapiterator Clone Returns a copy of the current mapiterator. A copy has independent life and initially is over the same element as the source iterator.
string Key Returns the unique key for the element of the map under the iterator.
Value Returns the element of the map under the iterator.
queue queue bool IsEmpty True if Count = 0, False otherwise.
Push[string] True if the item was pushed successfully.
int Count Number of items inserted onto the queue.
string Peek False is returned if IsEmpty is true.
Pop
set set bool Add[sequence] True is returned if the item(s) were added to the set.
Clear Removes all items from the set. True is always returned.
Contains[string] True is returned if the item is in the set.
Remove[string] True is returned if the item was removed from the set.
int Count Number of items added to the set.
setiterator Find[string] A setiterator is returned on the set where the current element under the iterator is the item if the item is in the set and an empty iterator if it is not.
First A setiterator is returned on the set where the current element under the iterator is the first element in the set if the set has elements or an empty iterator if the set is empty.
setiterator setiterator bool Advance The iterator is moved to the next item in the set, if one exists. True is returned if the iterator was advanced and False otherwise.
IsEnd True if the iterator is at the end of the set.
Reset Positions the iterator to the start of the set. True is always returned.
string Value Returns the element of the set under the iterator.
stack stack bool IsEmpty True if Count = 0, False otherwise.
Push[string] True if the item was pushed successfully.
int Count Number of items inserted onto the stack.
string Peek False is returned if IsEmpty is true.
Pop