local Diff = 0
local Compareitems = {}
for key1, value1 in pairs(Table) do local IsDifferent = false
for key2, value2 in pairs(Table2) do
table.insert(Compareitems,#Compareitems+1,{key2,value2})
if key1 == key2 then
for i = 1,#Compareitems do
local Item = Compareitems[i]
if Item[1] == key2 then
table.remove(Compareitems,i)
end
end
else
end
end
if IsDifferent then
Diff = Diff + 1
end
end
return Compareitems,Diff
end
-- Edit: I had the biggest brainfart while writing this.
You can just iterate through “a” and check the nodes in “b” (“a” is the default data from the system, “b” is the player data)
local a = {['YourNode1'] = 'YourValue1'; ['YourNode2'] = 'YourValue2'}
local b = {['YourNode2'] = 'RandomValue'}
for i,v in pairs(a) do
if b[i] then
-- HERE YOU KNOW A AND B HAS BOTH THE SAME NODE (KEY)
print(b, 'has node',i,'with value',v)
else
-- HERE YOU KNOW IT DO NOT CONTAINS
print(b, 'does not have node',i,'with value',v)
end
end
I also use this in my data system which is used on a published game with over 300k+ visits so it’s battle tested and work 100%
And how should I do this? That’s what I originally tried to do but got tangled up in all of the Keys and indices. If you could post some code that would be a huge help.
function update_structure(tbl,comparison_data)
for i,v in pairs(comparison_data) do
if tbl[i] and type(v) == 'table' then
update_structure(tbl[i],comparison_data[i])
else
tbl[i] = v
end
end
end
update_structure(b,a)
function create_interface(tbl)
local path = tbl
local interface = setmetatable({},{
__index = function(t,k)
if rawget(tbl,k) then
path = rawget(path,k)
return create_interface(rawget(tbl,k))
end
end;
__newindex = function(t,k,v)
print('Value '..k..' changed.')
rawset(path,k,v)
end;
})
return interface
end
local data = override_data_store and (get_attempt(self.UserId,0,override_data_store) or default_data()) or get_attempt(self.UserId,0) or default_data()
local interface = create_interface(data)
Thatt does not even make sense because one of the tables represent the default structure of the player data which is the system structure, it is a non-object-oriented data.