Need help with changing table reference value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So I have a table we call it A the table A is a Dictionary and contain a “Reference Table” to reference it with an empty table to reference the Table A.
    How the script look:
local B = {}
local C = {}

local A = {
	["Variable_B"] = {["Reference_Table"] = B,["Boolean"]=false},
	["Variable_C"] = {["Reference_Table"] = C,["Boolean"]=false},
	["Variable_D"] = {["Boolean"]=false}
  1. What is the issue? Include screenshots / videos if possible!
    I can’t the reference value in any ways for some reason and it only change the Variable Value instead of the Reference Value

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did actually make it work but somehow it just Won’t Work after I tested it another time?
    .I Also tried to Reference the Table inside the Table A but before I can do that the old methods doesn’t work anymore

local B = {} --Reference Table
local C = {}

local A = { --Main Table
	["B"] = {["Reference_Table"] = B,["Boolean"]=false}, --Others Table
	["C"] = {["Reference_Table"] = C,["Boolean"]=false},
	["D"] = {["Boolean"]=false} --Table with no Reference Table

local E = {["B"]=B,["C"]=C} -- A Temp Table to loop **not necessary**

for a:string,_ in pairs(A) do
	for b:string,_ in pairs(E) do
		if a == b then
			E[b] = A[a]

print(B,C) --Print the Reference Table
-- {},{}

print(E) --Print the Temp Table
-- Print E with A Variable
print(A) --Print the Main Table
-- Print A but no Table Cycle Reference detected
1 Like

I’m cloning table and need it to work in real time If Main Table Changed Then The Reference Table Change if I use table.insert I will need to manually add a new value when i update the Main Table. I’m trying like Make a Variable Reference one of the part of Main Table I can proabably do it manually by Setting Variable = MainTable[“Path”] but there too much to handles. If there no other methods then I might do the Manual way

Could you post what you expect the output to be, I’m having a hard time understanding what you want to happen. Everything so far is behaving normally, you are overwriting table references. If you just want a cyclical reference try this

local A = {}
local B = {
    child = A
A = {
    child = B

The Reference Table should be The Main Table. The for loop actually just search in the E and A Table then Search it Variables like E[“B”] or [“C”] and A also do the same It checks if both Variables are the same then Set the Reference Table in E Table But it only set it Value but not The Reference Table. If it work it should be like this

Your example works but I won’t set them outside of the Main Table but instead add a key in the Table as a filter so that for loop can do it things. But I can’t change the Reference Value or Table but I can only change the Value of the key. Setmetatable works for me but I need to use __index for others things and I can’t overlap 2 __index metamethods. I am just cloning Table to it Parent Table or rather set the Variable Value as the Main Table Value.

Or I just wanted to change the Table Value:

local OtherTable = {}
local Table = {
	["A_Key"] = OtherTable -- Now inside Table have a key that is holding a value that are referencing to OtherTable 

--Table["A_Key"]  = {["A"] = {}} --Change the value
--print(Table["A_Key"]) --Value has been changed
--print(OtherTable) --Other Table haven't been changed

for i,v in pairs(Table) do
	Table[i] = "A"

print(Table["A_Key"]) --Value has been changed
print(OtherTable) --Other Table haven't been changed

I tried many methods and it seem like it not possible even. Setmetatable works but I need to use __index for function __newindex doesnt work for me using __call works but it not perfect for typechecking. I guess I need to manually set it.