ID:2186384
 
(See the best response by Kaiochao.)
/mob/player

var/blindspots[][] = new/list(1, 2)


proc/Blindspots()
var/p
var/newy = y
var/newx = x
var/xref = x
var/loops = 0
var/ind = 1
if (dir == SOUTH)
for(p=0, p<6, p++)
newy = newy + 1
blindspots.Add(list(newx, newy))
if (loops)
for(p=0, p<loops, p++)
newx = newx + 1
blindspots.Add(list(newx, newy))
newx = xref
for(p=0, p<loops, p++)
newx = newx - 1
blindspots.Add(list(newx, newy))
newx = xref
loops++
ind++


Here's my code. The intent is to add the evaluated x and y variables to be used as a reference later. However, when I check the list using debug verbs, it's outputting blank lines and empty lists. Is my mistake apparent enough here to explain to me what I should be doing or what I'm doing wrong?
Best response
new /list (1, 2)

This makes a list that looks like this (in json notation):
[[null, null]]

That is, a list with 1 element, which is a list of 2 null elements. Probably not what you wanted.

Calling list.Add(list(x, y)) on the above list results in a list that looks like this:
[[null, null], x, y]

You may have been expecting the list to be inserted in the list like so:
[[null, null], [x, y]]

But according to the DM Reference,
Add proc (list):
If an argument is itself a list, each item in the list will be added.

You can add a list B as an element of list A with this:
A[++A.len] = B
Could you explain the mechanics of that last expression you're showing me? I looked up the info on the ++ pre and post increment operator, but the help on it doesn't seem right. It's saying if A = 0 and you A++, then A will still equal 0, but I've been using verbs and procs and ++ adds 1 to the var. Is ++A just A + 2 in shorthand?
It's essentially saying LIST A[INDEX + 1] = LIST B.
If A is an empty list, it will have a length (.len) of 0, so when you pre-increment it, list index 1, the first element of the list, will then be equal to list B. This will work for index 2, 3, and so on.

The difference between pre and post increment is when the increment takes place. ++x takes place before the expression is evaluated. x++ takes place after the expression is evaluated.

For example:

var/x = 4
if(++x > 4) world << "Returned true." //Returns true.
//x is now 5
if(x++ == 6) world << "Returned true." //Returns false.
//x is now 6

In response to Gooobai
It's the same as this:
A.len = A.len + 1
A[A.len] = B

The post-increment operator works as if those lines are reversed. The expression is evaluated using the original value of the variable, and then the variable is changed.
Would A++ and ++A at the end of a list of code end with the same result then? For example:

A = 1
A++
//A now == 2

A = 1
++A
//A now == 2
In response to Gooobai
Yup.