I want to share a table between two scripts. It is important that it is referencing to the same script. Like in testA. I first tried coding it like testB and discovered that it wasn't working. I am why a BinadableFunction returns a different table in testB? And is there a better way to get the behavior of testA? Below I have put some code.
function testA()
local a = {value=1}
local bindableFunction = script.Parent.BindableFunction
local function getTheValueA()
return a
end
local function getTheFunctionWhichGetTheValueA()
return getTheValueA
end
bindableFunction.OnInvoke = getTheFunctionWhichGetTheValueA
local aFromBindableFunction = bindableFunction:Invoke()() --Ofcourse this method would be called by another script but this is a demonstration.
print(a) --table: 0x34f4b809cbd233e9
print(aFromBindableFunction) --table: 0x34f4b809cbd233e9
print(a.value) --1
print(aFromBindableFunction.value) --1
a.value=2
print(a.value) --2
print(aFromBindableFunction.value) --2
end
function testB()
local a = {value=1}
local bindableFunction = script.Parent.BindableFunction
local function getTheValueA()
return a
end
bindableFunction.OnInvoke = getTheValueA
local aFromBindableFunction = bindableFunction:Invoke()
print(a) --table: 0xf6477616a42fdf39
print(aFromBindableFunction) --table: 0x93e49c7250a1d539
print(a.value) --1
print(aFromBindableFunction.value) --1
a.value=2
print(a.value) --2
print(aFromBindableFunction.value) --1
end
testA()
print("----------------------------------")
testB()
