Hey guys,
I have my game mechanics setup in a “game.lua” and I also have another lua file called “levels.lua”
now in the “levels.lua” file there are tables for each level that contain the necessary data for that level
basically my “levels.lua” file looks like this:
local M = {}
local boardLevel1 = {
{1,4,4,2,4,6,6,5},
{3,2,3,3,2,1,3,4},
{2,3,1,4,4,5,3,5},
{2,4,3,4,1,3,1,1},
{3,6,3,1,6,1,3,4},
{1,5,6,2,1,2,6,2},
{6,2,2,4,2,5,2,4},
{1,1,4,1,3,4,4,1},
}
local boardLevel2 = {
{5,4,6,2,4,3,2,5},
{3,2,3,3,2,1,3,4},
{2,4,1,5,4,5,4,5},
{2,4,3,4,1,3,1,1},
{3,6,3,1,6,7,3,4},
{1,2,6,2,1,2,6,2},
{6,2,2,2,2,5,2,4},
{5,1,6,1,3,1,4,3},
}
return M
What im trying to do is, to copy the correct board to the “game.lua” file
I have a variable and a table(in the “game.lua” file) :
local levelNum=0
local board = {
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
}
I want to copy the correct table from the “levels.lua” to the ‘board’ in the “game.lua”
I try this:
local function copyArray()
for i=1 , 8 do
for j=1 , 8 do
board[i][j]=levels.boardLevel…levelNum[i][j]
end
end
end
copyArray()
But its not working, any suggestion how to do this?
Roy.
EDIT:
Managed to get it to work…