I'm trying to use a for loop to go through all the variables in a list that contains multiple lists, as shown :

    var/grid = new/list(10,5)
for(i in grid)
i = "X"
usr << grid[1][1]

The problem is that the user receives nothing. This is not a skin issue either, I have tested that.

Any ideas on how to do this? Thanks
Two things:

1. Setting i = "X" doesn't change what's stored in the list because "i" is just a reference to a value. You're changing the value of "i", the value that reference points to, not the value in the list. Even with a simple list this wouldn't work:

var/list/L = list(1, 2, 3, 4)
for(var/n in L)
n += 1
world << "[L[1]], [L[2]], [L[3]], [L[4]]"

That doesn't change the values in the list.

2. The grid var is a list where each element is also a list. When you say "for(i in grid)" you're iterating over a set of 10 lists.

You'd want to do something like this:

for(var/i = 1 to 10)
for(var/j = 1 to 5)
grid[i][j] = "X"
In response to Forum_account
Ah, thanks for that. Makes perfect sense now.