Using Lists

From QuestWiki
Jump to: navigation, search

Lists are made up of any number of strings (for a stringlist) or objects (for an objectlist).

Lists can be created by the NewStringList or NewObjectList functions, or can be returned by functions such as the scope functions.

Example of generating an objectlist called myList and an empty stringlist called MyStringList:

myList = ScopeVisibleNotHeld()
myStringList = NewStringList()

An object or string can be retrieved from a list by its index using ObjectListItem or StringListItem. For example, to retrieve the second item from the above list (remembering that they count from zero):

StringListItem(myStringList, 1)

A string list can be converted to a string using the Join function. Conversely, a string can be broken up into a string list using the Split function.

Iterating through list elements

You can read a list in several ways. Note that lists are indexed from zero, so the item at index 2 will actually be the 3rd element.

foreach (item, ScopeVisible()) {
  msg ("The item is "+item.name)
}
for (myItem, 0, ListCount(myList) - 1) {
  msg ("Current item is " + ObjectListItem(myList,myItem).name)
}

Adding and removing items

To manipulate the list use add and remove commands.

if (ListContains(myList, player) {
  list remove(myList, player)            
}
list add(myStringList,"Text item 1")
list add(myStringList,"Text item 2")            

Combining lists

To combine two lists into one, use the ListCombine function.

To return a copy of a list with one element removed, use the ListExclude function.

Personal tools
Namespaces
Variants
Actions
Navigation
Quest Documentation
Toolbox