function DataStoreModule:setData(key,data,value)
--key would mean b in this example
a[key][data] = value
end
I want to set Test, that should be located under c to false Test = false
Normally this would work a[key(means b)][c][d][Test] = false (value)
but I can only pass data trough the function[ function DataStoreModule:setData(key,data,value)]
How can I pass that [[c][d][Test]] trough data and how can I place data so this [a[key(means b)][c][d][Test] = false (value)] works?
My bad I’m blind, could be missing something but I believe it’s not possible to do it that way, currently very low on battery so I’ll come back later and try to help more if You still haven’t found a solution
You can modify the function to your needs. Also your current explanation of the problem is pretty much an XY problem (XY problem - Wikipedia). You’d typically be better off showing the actual code and explaining the actual use for what you’re trying to do, instead of rounding the problem up to what you think it is.
The easiest solution would probably be to pass the entirety of the “b” table to be saved, so that you don’t have to worry about sorting through all of the nesting.
You could also use a sort of compounded key to search through the table using a method like this:
local a = {
b = {
c = {
Test = true;
d = {
}
}
}
}
local function ChangeData(key, data, value)
local tblToChange = a
for _, nextKey in string.split(key, "_") do
tblToChange = tblToChange[nextKey]
end
tblToChange[data] = value
end
ChangeData("b_c", "Test", false)
print(a)