I am trying to learn oop and I don’t seem to understand how to insert value in a dictionaty on an oop system.
I want to know how to add stuff inside a dictionary with a function called “Add” and get the values out of it.
But when I try to do it myself like this it shows that the dictionary I am printing is nill!
Module Scipt,
local module = {}
module.__index = module
function module.new(GenWithLocation)
return setmetatable({
Assigned = {}
}, module)
end
function module:Add(generatorObj, locationObj)
table.insert({[generatorObj] = locationObj}, self.Assigned)
end
function module:Print()
for i, v in pairs (self.Assigned) do
print(i.Name..' = '..v.Name)
end
end
return module
Server Script,
wait(8)
print("S")
local mod = require(game.ServerScriptService.Hydroplant)
mod.new()
mod:Add(workspace.Generator1, workspace.Baseplate)
mod:Print()
mod:Add(workspace.Generator1, workspace.Baseplate)
mod:Print()
Both scripts are in ServerScriptService