Hi all.
I created a class. It has a class structure. For example inventory, weapons, car, whatever. I need to return the structure from the class.
The autocomplete should work.
No matter what I do, I get the same array back. I need different ones.
Class
local Class = {}
local Struct = {
name = "Def name",
descr = "Text",
max = 110,
def = 1,
val= 0,
};
function TCopy(t)
local r = {}
for k, v in pairs(t) do
r[k] = v
end
return r
end
function Class.new()
local ReturnStruct = Struct;
--If you copy the original table, everything works correctly. But it's not a pretty solution.
--Struct=TCopy(Struct);
return ReturnStruct;
end
function Class.GetState()
return 1;
end
return Class;
Include
local CLASS_Test = require(script.Parent.CLASS_Test);
local Obj1 = CLASS_Test.new();
local Obj2 = CLASS_Test:new();
Obj2.name ="BB2";
print(Obj1.name, Obj2.name)
if(Obj1.name ~= Obj2.name)then
warn("This work");
else
warn("It is the same object.");
end
Autocomlete. That’s what I mean.