-
Notifications
You must be signed in to change notification settings - Fork 0
Length
PeerHeer edited this page Dec 31, 2019
·
8 revisions
Finding the length of a list can be done with the data get command combined with execute store result, which is built-in and not used by List Utils. For dynamic uses, you can use data get storage|block|entity <identifier> <path>.
Errors that display when executing the command from chat.
| Error | Message |
|---|---|
| Element does not exist | Found no elements matching <element> |
| Objective does not exist | Unknown scoreboard objective '<objective>' |
The value returned using execute store result represents either the value of the element for numeric values, or the length of the element for all other values.
Take the example list ExampleList: ["foo", "Hello World!", "foo", "bar"] in the listutils:examples storage. We want to find its length and store it in the $length lenghtObj score:
execute store result score $length lengthObj run data get storage listutils:examples ExampleListThis will result in a $length lenghtObj score of 4.