Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't I access my table values outside of a for loop?

Asked by 7 years ago
local grid = {}

for n = 1, gridX do 

    grid[n] = {};

    for i = 1, gridY do

        --Uses the generation module to spawn one tile per loop iteration.
        --The module takes in the tile type, and the 'x' and 'y' co-ordinates.
        --The 'x' and 'y' co-ordinates are 4 (the size of the tile) plus .1 for spacing, multiplied
        local currentTile = grid[n][i]
        local generatedTile = generationModule.SpawnTile("Plains", -i * 4.1, -n * 4.1);
        currentTile =   {
                            x = n,
                            y = i,
                            tile = generatedTile
                        };

        --All working fine
        print(currentTile.tile.Name);       
        print(grid[n][i]);      


        currentTile.label = currentTile.tile.Gui.Text;

    end
end


--Throws "attempt to index field '?' (a nil value)" error
grid[5][3].tile.Name = "lol";

Self explanatory really

Answer this question