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

Description

The listutils:data_at function finds the element at an index.

Usage

Input is given using the listutils:in storage:

Field Meaning
List The list that contains the index.

Additionally, the index should be put in the $listutils.index listutils.in score. Negative indices will have the same behavior as using them in a static context.

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

Errors

Errors that display when executing the listutils:data_at 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.

Result

The result of the operation is stored inside the Data field in the listutils:out storage.

Example

Take the example list ExampleList: ["foo", "Hello World!", "foo", "bar"] in the listutils:examples storage. We want to find the element at index 1:

# Add List to the input.
data modify storage listutils:in List set from storage listutils:examples ExampleList
# Add the index to the input.
scoreboard players set $listutils.index listutils.in 1
# Call the function.
function listutils:data_at

This would return "Hello World!" inside the Data field in the listutils:out storage.

Clone this wiki locally