Good day, I was wondering why is my table being altered even though I set it as a use of reference for other table. Sample:
tableCopy.lua
local M = {} local origTable = loadTableFromJson M.copyTable = function() local otherTable = origTable return otherTable end return M
main.lua
local tableCopy = require("tableCopy") local myTable = {} myTable = tableCopy.copyTable() myTable.hp = myTable.hp - 1 -- Output is from 10 to 9 local newTable = tableCopy.copyTable() newTable.hp = newTable.hp - 1 -- Output is 8, the hp still retains
as you can see, the hp still continues even though, in my copyTable.lua I’m just copying the table. I already solved it by just reReading the JSON again, just asking why does this happen?
thanks in advance