function love.load()
tab1 = {}
tab1[1] = {a=1,b=1}
tab1[2] = {a=5,b=6}
tab2 = {}
tab2[1] = {tab1 = tab1}
tab2[2] = {tab1 = tab1}
end
function love.update(dt)
tab2[2].tab1[1].a = tab2[2].tab1[1].a + 1
print("tab1 is " .. tab2[1].tab1[1].a .. "tab2 is " .. tab2[2].tab1[1].a)
end
tab[1].a changes too, i want it to work like tab2[2].tab1[1].a and tab2[1].tab1[1] are separate things? I hope you guys understand me, because english isnt my native languague :/
likemau5 wrote:Hi guys. I want to make a table with some data, and then make few tables containing the 1st table, and then make operations on them separately(?)
function love.load()
tab1 = {}
tab1[1] = {a=1,b=1}
tab1[2] = {a=5,b=6}
tab2 = {}
tab2[1] = {tab1 = tab1}
tab2[2] = {tab1 = tab1}
end
function love.update(dt)
tab2[2].tab1[1].a = tab2[2].tab1[1].a + 1
print("tab1 is " .. tab2[1].tab1[1].a .. "tab2 is " .. tab2[2].tab1[1].a)
end
tab[1].a changes too, i want it to work like tab2[2].tab1[1].a and tab2[1].tab1[1] are separate things? I hope you guys understand me, because english isnt my native languague :/
lua and tables just work like that, if you want to copy a table you need to explicitly create a new table: