dugasz1 Posted December 3, 2014 Share Posted December 3, 2014 Hi! asdd = { {"egy", "ketto", "három"}, {"egy1", "ketto1", "három1"}, {"egy1", "ketto1", "három1"}, } function wasd2 () local asddCopy = asdd outputChatBox(asdd[2][3])-- Output: teszt asdd[2][3] = "teszt" outputChatBox(asdd[2][3].."|"..asddCopy[2][3])-- Output: teszt|teszt end addCommandHandler("teszt3", wasd2) Now i noticed that if i copy a table and i overwrite a value in the new table(asddCopy) , the first table(asdd) value is change too. Why? And how can i solve to not change the first table's(asdd) value? Link to comment
Feche1320 Posted December 3, 2014 Share Posted December 3, 2014 That is becouse you are indexing the table (pointing that table to the copy table).. To avoid this you can do it by copying the table asdd = { {"egy", "ketto", "három"}, {"egy1", "ketto1", "három1"}, {"egy1", "ketto1", "három1"}, } function wasd2 () local asddCopy = deepcopy(asdd) outputChatBox(asdd[2][3])-- Output: teszt asdd[2][3] = "teszt" outputChatBox(asdd[2][3].."|"..asddCopy[2][3])-- Output: teszt|teszt end addCommandHandler("teszt3", wasd2) function deepcopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in next, orig, nil do copy[deepcopy(orig_key)] = deepcopy(orig_value) end setmetatable(copy, deepcopy(getmetatable(orig))) else -- number, string, boolean, etc copy = orig end return copy end Link to comment
dugasz1 Posted December 3, 2014 Author Share Posted December 3, 2014 Ohh end one other question. Can i index/link a value to another value in a table? asdd = { {1, 2, 3}, --if v[1][1] value change {4, 5, 6}, {7,8, --[[asdd[1][1] + 1]]}, -- v[3][3] value change to but if in inverse way don't } Someting like this. I hope, i could explain my problem clearly. Link to comment
Feche1320 Posted December 3, 2014 Share Posted December 3, 2014 Ohh end one other question. Can i index/link a value to another value in a table? asdd = { {1, 2, 3}, --if v[1][1] value change {4, 5, 6}, {7,8, --[[asdd[1][1] + 1]]}, -- v[3][3] value change to but if in inverse way don't } Someting like this. I hope, i could explain my problem clearly. Sorry I did not understand Link to comment
dugasz1 Posted December 3, 2014 Author Share Posted December 3, 2014 So, i want to call a value from asdd table and use it in asdd table like a variable. Is it possible? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now