Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions content/objects/list/proc/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,31 @@
title = "Add"
slug = "Add" # AUTOGEN FIELD
[[extra.args]]
name = "Item1" # AUTOGEN STATIC
+++
name = "Item1, Item2, ..."
description = "One or more values to add"
+++

Adds a value, or multiple values, to the list.

```dm
var/list/L = list(1, 2)

L.Add(3)
world.log << json_encode(L) // "[1,2,3]"

L.Add(4, 5)
world.log << json_encode(L) // "[1,2,3,4,5]"
```

If any of the values are another list then the contents of that list will be added rather than the list itself.

```dm
var/list/L1 = list(1, 2)
var/list/L2 = list(3, 4)

L1.Add(L2)

// "[1,2,3,4]"
// NOT "[1,2,[3,4]]"
world.log << json_encode(L1)
```
15 changes: 14 additions & 1 deletion content/objects/list/proc/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ slug = "Copy" # AUTOGEN FIELD
[[extra.args]]
name = "Start" # AUTOGEN STATIC
default_value = "1" # AUTOGEN FIELD
description = "Index of the first element to be included in the copy"
[[extra.args]]
name = "End" # AUTOGEN STATIC
default_value = "0" # AUTOGEN FIELD
+++
description = "Index past the last element to be included in the copy, or 0 for the last element"
[extra.return]
description = "A shallow copy of the list"
+++

Returns a new shallow copy of the list.

```dm
var/list/L1 = list(1, 2, 3)
var/list/L2 = L1.Copy(2)

world.log << json_encode(L2) // "[2,3]"
```
13 changes: 12 additions & 1 deletion content/objects/list/proc/cut.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ slug = "Cut" # AUTOGEN FIELD
[[extra.args]]
name = "Start" # AUTOGEN STATIC
default_value = "1" # AUTOGEN FIELD
description = "Index of the first element to be cut from the list"
[[extra.args]]
name = "End" # AUTOGEN STATIC
default_value = "0" # AUTOGEN FIELD
+++
description = "Index past the last element to be cut from the list, or 0 for the last element"
+++

Removes the indicated elements from the list.

```dm
var/list/L = list(1, 2, 3, 4)
L.Cut(2, 4)

world.log << json_encode(L) // "[1,4]"
```
16 changes: 15 additions & 1 deletion content/objects/list/proc/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ name = "Elem" # AUTOGEN STATIC
[[extra.args]]
name = "Start" # AUTOGEN STATIC
default_value = "1" # AUTOGEN FIELD
description = "Index of the first element to be included in the search"
[[extra.args]]
name = "End" # AUTOGEN STATIC
default_value = "0" # AUTOGEN FIELD
+++
description = "Index past the last element to be included in the search, or 0 for the last element"
[extra.return]
type = "num"
description = "The index of the found element, or 0"
+++

Search for the given item in the list. If any values in the list are equal, this will return its index. Otherwise it will return 0.

```dm
var/list/L = list(10, 20, 30, 20)

// Will return the first instance of 20
world.log << L.Find(20) // 2
```
20 changes: 19 additions & 1 deletion content/objects/list/var/len.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@ title = "len"
[extra]
default_value = "" # AUTOGEN FIELD
is_override = false # AUTOGEN FIELD
+++
+++

The length of the list. Accessing this gives you the amount of values the list contains.

Changing this value resizes the list, which will remove elements beyond the specified length if the list is shrunk, or grow the list with null values.

```dm
var/list/my_list = list("foo", "bar", "car")
my_list.len = 2

for(var/element in my_list)
world.log << element // "foo", "bar"

var/list/my_other_list = list("foo")
my_other_list.len = 3

for(var/element in my_list)
world.log << isnull(element) // FALSE (0), TRUE (1), TRUE (1)
```
Loading