[SOLVED] Accessing table from a different Lua file?

I posted 2nd post also

This return { … } is the same as wrapping in levels0To100 table

What I did is this:

[lua]

local levels0To100 ={

    level0={

        boardLevel = {

            {1,3,3,1,5,2,1,2},

            {3,2,3,3,2,2,3,4},

            {2,5,5,6,4,6,4,6},

            {4,4,1,3,2,5,1,1},

            {4,4,2,1,1,3,1,3},

            {3,3,5,6,2,2,3,2},

            {6,2,2,6,2,5,2,4},

            {1,1,4,5,1,4,4,1},

            }

            

        ,BoardShapeID=2

        ,GameType = 0

        ,TimeLeft = 30 

        ,GameTarget = 2 

        ,MovesLeft = 0 }

    ,level1={

        boardLevel = {

            {1,3,3,1,5,2,1,2},

            {3,2,3,3,2,2,3,4},

            {2,5,6,5,5,6,4,6},

            {3,2,3,4,1,3,1,1},

            {3,6,6,4,2,5,1,3},

            {1,3,6,3,1,1,6,2},

            {6,2,5,6,2,6,2,4},

            {1,1,4,5,3,4,4,1},

            }

        

        ,BoardShapeID=17

        ,GameType = 1 

        ,TimeLeft = 60 

        ,GameTarget = 1500

        ,MovesLeft = 0 }

}

local M = {}

–levels declaration

M[“levels0To100”] = levels0To100

return M

[/lua]

Then in my gameplay.lua file I take the data like so:

[lua]

local mydata = require(“mydata”) 

local currGameData = mydata[“levels0To100”][“level”…_levelNum]

[/lua]

It works.

Roy.

Just some note. When you require some file for the first time - then this file is executed like any normal file (you could even draw some objects - it would executs it as any normal code). If you return something from required file then this is returned as from function and this returned value is remembered.
If you require file again - then this file won’t be executed second time! You will just get this remembered value and that’s all.

Hehe, just saying but you can also have it like this (just to show it’s possible)

local M = { levels0To100 = levels0To100, } return M

Lua’s
data.levels0To100 is equal to data[“levels0To100”]

Great Info, thank you VERY MUCH!

Roy.