Skip to content

Commit 3fcddc8

Browse files
authored
Some list documentation (#129)
Documented `len`, `Add()`, `Copy()`, `Cut()`, and `Find()`
1 parent 2a59e68 commit 3fcddc8

File tree

5 files changed

+88
-6
lines changed

5 files changed

+88
-6
lines changed

content/objects/list/proc/add.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,31 @@
22
title = "Add"
33
slug = "Add" # AUTOGEN FIELD
44
[[extra.args]]
5-
name = "Item1" # AUTOGEN STATIC
6-
+++
5+
name = "Item1, Item2, ..."
6+
description = "One or more values to add"
7+
+++
8+
9+
Adds a value, or multiple values, to the list.
10+
11+
```dm
12+
var/list/L = list(1, 2)
13+
14+
L.Add(3)
15+
world.log << json_encode(L) // "[1,2,3]"
16+
17+
L.Add(4, 5)
18+
world.log << json_encode(L) // "[1,2,3,4,5]"
19+
```
20+
21+
If any of the values are another list then the contents of that list will be added rather than the list itself.
22+
23+
```dm
24+
var/list/L1 = list(1, 2)
25+
var/list/L2 = list(3, 4)
26+
27+
L1.Add(L2)
28+
29+
// "[1,2,3,4]"
30+
// NOT "[1,2,[3,4]]"
31+
world.log << json_encode(L1)
32+
```

content/objects/list/proc/copy.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ slug = "Copy" # AUTOGEN FIELD
44
[[extra.args]]
55
name = "Start" # AUTOGEN STATIC
66
default_value = "1" # AUTOGEN FIELD
7+
description = "Index of the first element to be included in the copy"
78
[[extra.args]]
89
name = "End" # AUTOGEN STATIC
910
default_value = "0" # AUTOGEN FIELD
10-
+++
11+
description = "Index past the last element to be included in the copy, or 0 for the last element"
12+
[extra.return]
13+
description = "A shallow copy of the list"
14+
+++
15+
16+
Returns a new shallow copy of the list.
17+
18+
```dm
19+
var/list/L1 = list(1, 2, 3)
20+
var/list/L2 = L1.Copy(2)
21+
22+
world.log << json_encode(L2) // "[2,3]"
23+
```

content/objects/list/proc/cut.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ slug = "Cut" # AUTOGEN FIELD
44
[[extra.args]]
55
name = "Start" # AUTOGEN STATIC
66
default_value = "1" # AUTOGEN FIELD
7+
description = "Index of the first element to be cut from the list"
78
[[extra.args]]
89
name = "End" # AUTOGEN STATIC
910
default_value = "0" # AUTOGEN FIELD
10-
+++
11+
description = "Index past the last element to be cut from the list, or 0 for the last element"
12+
+++
13+
14+
Removes the indicated elements from the list.
15+
16+
```dm
17+
var/list/L = list(1, 2, 3, 4)
18+
L.Cut(2, 4)
19+
20+
world.log << json_encode(L) // "[1,4]"
21+
```

content/objects/list/proc/find.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ name = "Elem" # AUTOGEN STATIC
66
[[extra.args]]
77
name = "Start" # AUTOGEN STATIC
88
default_value = "1" # AUTOGEN FIELD
9+
description = "Index of the first element to be included in the search"
910
[[extra.args]]
1011
name = "End" # AUTOGEN STATIC
1112
default_value = "0" # AUTOGEN FIELD
12-
+++
13+
description = "Index past the last element to be included in the search, or 0 for the last element"
14+
[extra.return]
15+
type = "num"
16+
description = "The index of the found element, or 0"
17+
+++
18+
19+
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.
20+
21+
```dm
22+
var/list/L = list(10, 20, 30, 20)
23+
24+
// Will return the first instance of 20
25+
world.log << L.Find(20) // 2
26+
```

content/objects/list/var/len.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,22 @@ title = "len"
33
[extra]
44
default_value = "" # AUTOGEN FIELD
55
is_override = false # AUTOGEN FIELD
6-
+++
6+
+++
7+
8+
The length of the list. Accessing this gives you the amount of values the list contains.
9+
10+
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.
11+
12+
```dm
13+
var/list/my_list = list("foo", "bar", "car")
14+
my_list.len = 2
15+
16+
for(var/element in my_list)
17+
world.log << element // "foo", "bar"
18+
19+
var/list/my_other_list = list("foo")
20+
my_other_list.len = 3
21+
22+
for(var/element in my_list)
23+
world.log << isnull(element) // FALSE (0), TRUE (1), TRUE (1)
24+
```

0 commit comments

Comments
 (0)