List Basics
Lists are extra powerful variables. Instead of just a single name referring to a single value, lists can refer to multiple values, they can be looped, added to, cleared, and treated as if they're much more than just a single value. These properties make lists extremely useful for store data that changes per player, for data that requires a bunch of know locations, like warps, homes, or generator locations. Plus, when you're done with the data you can just delete it all at once!
Values, Indices, and ::*
::*
Let's start by introducing some definitions, so we're all on the same page. Lists, in Skript, are variables that use the ::
separator. In most cases, it'll look like {_my-list::*}
. This ::*
means "get all the values of the list _my-list
". Values are the things you store in your list. These could be numbers, locations, text, or any combination. Each value in a list also has a corresponding name, an index. You can use this index to access that value specifically. By default, the indices of a list will be from 1 to however long the list is. Here's an example:
Using these indices, we can get a value separately from all the other values, by naming it specifically:
We can also set the index of a value to whatever we want. This is especially useful for storing information that's attributed to something else, like a player's last death location:
Using lists like this makes it simple to see all the last death locations at once ({last-death::*}
), and as you'll see in a second, makes it really easy for us to reset everything if we decide this information is no longer useful.
Lists are also very useful for sending information to a certain group of people:
Or sending a bunch of things all at once:
Of course, these same properties extend to other effects too. You can equip a player with a list of armors, give them a list of items, kill a list of entities, and much more.
Looping, Adding, Clearing, and Removing
This is where the major power of lists comes into play. Lists can be easily modified by adding and removing values, and they can be looped to provide easy access to all the values.
We have the normal changers:
In a similar vein, there's also a condition called contains
which will allow you to check if a value is contained somewhere in a list:
We can also loop lists, which opens up even more possibilities:
In this code, we loop through a list, sending the index and the value each time. Our output will look something like this:
This can be really useful for things like leaderboards, for knowing what elements exist in your list, and much more. If you want to see some more advanced uses of lists, ways to best optimize them, as well as some of the quirks and trickier aspects of using them, check out the Lists page.
Last updated