Lists
Lists and maps, for keeping several values together.
all players
A list of every player on the server right now. Go through it with for each to do something to everyone.
Gives back: Player>
Script: onlinePlayers()
players in [World]
A list of the players in one world right now. Use all players instead to include every world.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | World | The world to look in. |
Gives back: Player>
Script: world.getPlayers()
add [any value] to [list]
Adds an item to the end of a list. A list holds at most 10,000 items; adding past that stops the script with an error.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The item to add. |
| 2 | list | The list to add to. |
Script: list.add(value)
insert [any value] at [number] in [list]
Puts an item into a list at a position, moving everything from there onwards one place along. Positions count from 0, and the position just past the last item adds to the end. Any other position, or going past 10,000 items, stops the script with an error.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The item to insert. |
| 2 | number | Where to put the item, counting from 0. |
| 3 | list | The list to insert into. |
Script: list.insert(number, value)
item [number] of [list]
The item at a position in a list. Positions count from 0, so the first item is 0 and the last is the length minus 1. A position outside the list stops the script with an error.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | number | Which position, counting from 0. |
| 2 | list | The list to read from. |
Gives back: any value
Script: list.get(number)
set item [number] of [list] to [any value]
Replaces the item at a position in a list. Positions count from 0. A position outside the list stops the script with an error; use add to grow the list.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | number | Which position to replace, counting from 0. |
| 2 | list | The list to change. |
| 3 | any value | The new item. |
Script: list.set(number, value)
remove item [number] of [list]
Removes the item at a position in a list, closing the gap. Positions count from 0. A position outside the list stops the script with an error.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | number | Which position to remove, counting from 0. |
| 2 | list | The list to remove from. |
Script: list.removeAt(number)
remove [any value] from [list]
Removes the first item in a list that is equal to the given value. Does nothing if there is none. Numbers match by value, so 2 and 2.0 are the same.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The value to look for and remove. |
| 2 | list | The list to remove from. |
Script: list.remove(value)
length of [list]
How many items a list holds. An empty list has length 0.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | list | The list to count. |
Gives back: number
Script: list.size()
[list] contains [any value]
Whether a list holds an item equal to the given value. Numbers match by value, so 2 and 2.0 are the same.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | list | The list to search. |
| 2 | any value | The value to look for. |
Gives back: true/false
Script: list.contains(value)
position of [any value] in [list]
The position of the first item in a list equal to the given value, counting from 0, or -1 if it is not there.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The value to look for. |
| 2 | list | The list to search. |
Gives back: number
Script: list.indexOf(value)
clear [list]
Removes every item from a list, leaving it empty.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | list | The list to empty. |
Script: list.clear()
set [any value] in [map] to [any value]
Stores a value in a map under a key, replacing whatever was stored under that key before. Number keys match by value, so 1 and 1.0 are the same key. A map holds at most 10,000 keys; adding past that stops the script with an error.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The key to store the value under. |
| 2 | map | The map to store into. |
| 3 | any value | The value to store. |
Script: map.put(value, value)
[any value] in [map]
The value stored in a map under a key, or nothing if the key is not there.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The key to look up. |
| 2 | map | The map to read from. |
Gives back: any value
Script: map.get(value)
remove [any value] from [map]
Removes a key and its value from a map. Does nothing if the key is not there.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | any value | The key to remove. |
| 2 | map | The map to remove from. |
Script: map.remove(value)
[map] has [any value]
Whether a map has a value stored under a key, even if that value is nothing.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | map | The map to check. |
| 2 | any value | The key to look for. |
Gives back: true/false
Script: map.has(value)
keys of [map]
A new list of every key in a map, in the order they were first added. Changing the list does not change the map.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | map | The map to list the keys of. |
Gives back: list
Script: map.keys()
values of [map]
A new list of every value in a map, in the order their keys were first added. Changing the list does not change the map.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | map | The map to list the values of. |
Gives back: list
Script: map.values()
size of [map]
How many keys a map holds. An empty map has size 0.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | map | The map to count. |
Gives back: number
Script: map.size()
clear [map]
Removes every key and value from a map, leaving it empty.
| Slot | Takes | What it is for |
|---|---|---|
| 1 | map | The map to empty. |
Script: map.clear()