Skip to content
PeerHeer edited this page Dec 31, 2019 · 7 revisions

Description

The listutils:count function checks how many times an element occurs in a list.

Usage

Input is given using the listutils:in storage:

Field Meaning
List The list that could contain the element.
Data The element that could occur in the list.

After defining the input, run the function listutils:count.

Comparison functions

Various comparison functions can be used to match elements. For more about comparison functions, see the Comparison Functions page.

Errors

Errors that display when executing the listutils:count function as a player in debug mode.

Error Message
TBD TBD

Return values

Success

The success of the operation is stored in the $listutils.success listutils.out score. This score is 1 on success and 0 otherwise. Success will be 0 when the list does not contain the element.

Result

The result of the operation is stored in the $listutils.result listutils.out score. The result is equal to the amount of times the element occurred in the list.

Example

Take the example list ExampleList: ["foo", "Hello World!", "foo", "bar"] in the listutils:examples storage. We want to find out how many times it contains "foo":

# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add Data to the input.
data modify storage listutils:in Data set value "foo"
# Call the function.
function listutils:count

This will return a result of 2 in the $listutils.result listutils.out score, since the list contains the string "foo" two times.

Clone this wiki locally