Tutorial by: Goose


A Guide to learning List Variables

Table of Contents

What are List Variables?

To put it simply, list variables are variables that hold multiple values. List variables look like {list::*}, and can be manipulated using the Change Effect.

Why should I use List Variables?

List variables should be used because it's a better practice than using period separated variables (for example, {kills.%player's uuid%}), and provide a wider variety of features, like looping through values, sorting values, deleting values in mass, and more.

How do I use List Variables?

We can think of list variables like a room, where every value in the list could be either another room, or be represented by a cardboard box. These cardboard boxes also have labels, or indexes. Here's several example uses of a list variable.

# This variable is a room, with another room in it, which contains three cardboard boxes, labeled 1, 2, and 3. In each cardboard box is "a", "b", or "c", respectively.
set {room1::room2::*} to "a", "b", and "c"

# Now let's try manipulating this list variable!
add "d" to {room1::room2::*}
remove "a" from {room1::room2::*}
set {room1::room2::5} to "e"
delete {room1::room2::*}
set {room1::christmasList::*} to "SkriptHub merchandise", "Ugly christmas socks", and "Pringles"
delete {room1::*} # Would also delete {room1::christmasList::*}

# We can also access parts of a list variable.
first element in {room1::christmasList::*}
last element in {room1::christmasList::*}
random element in {room1::christmasList::*}
{room1::christmasList::2} # if we wanted to get a value at a specific index

# Programmers, beware!
#If we have a variable with the following indices & values, for example:
#1: "a",
#2: "b",
#3: "c"

#Nothing is wrong here. However, if we remove the first element, it would then look like:
#1: "b",
#2: "c"

#Right..? Wrong! Skript does NOT organize the indices of a list when elements are removed from the variable. Instead, our variable would look like:
#1: <none>,
#2: "b",
#3: "c"

Example Usage of List Variables

# A simple queue script.
command queue:
    usage: &7Invalid usage. Please use /queue.
    trigger:
        if {queue::*} contains player's uuid:
            remove player's uuid from {queue::*}
            send "&7You've left the queue."
            stop
        add player's uuid to {queue::*}
        send "&7You've joined the queue."

command listqueue:
    permission: admin.listqueue
    permission message: &7Insufficient permissions.
    usage: &7Invalid usage. Please use /queue.
    trigger:
        send "&7Here's the entire queue:"
        loop {queue::*}:
            send "&7- &f%loop-value parsed as offlineplayer%"

Did you find Goose's tutorial helpful?


You must be logged in to comment

  • Dec. 5, 2021, 3:43 a.m. - Xna  

    Good Tutorial! I suggest you go a litttttle bit deeper inside list variables but pretty much summarizes what list variables are

    |     
  • Dec. 23, 2022, 9:11 p.m. - khamdaman  

    i made an account to dislike this

    |     
  • Feb. 9, 2024, 11:39 a.m. - dj_dogos  

    what i can use with:

    "first element in {room1::christmasList::}
    last element in {room1::christmasList::
    }
    random element in {room1::christmasList::*}"

    i dont understand where i can use it or how can i use it ?

    |