Hello! I am currently wondering how it would be possible to use my current function:
local function IncrementAttribute(InstanceLocation, AttributeName, Incremented)
InstanceLocation:SetAttribute(AttributeName, InstanceLocation:GetAttribute(AttributeName) + Incremented)
end
No Iâm talking about constructing proxy instances which you interact with instead of interacting with the original object.
Here is an elementary wrapping function:
local function Wrap(Object, Interface)
local Proxy = newproxy(true)
local Meta = getmetatable(Proxy)
function Meta:__index(Key)
return Interface[Key] or Object[Key]
end
function Meta:__newindex(Key, Value)
Object[Key] = Value
end
return Proxy
end
I could use this to wrap Workspace to give the interface of being a âSwagObjectâ and a âWorkspaceâ
This would not be worth using in my opinion because this would be extra code than all of the :IncrementAttribute()'s I would use in 1 script. Thanks anyway.
You can use OOP (Object Oriented Programming) and ModuleScripts to achieve this.
local Module = {}
Module.__index = Module
function Module.new()
local NewModule = setmetatable({}, Module)
NewModule.RandomVariable = 5
return NewModule
end
function Module:PrintVariable()
print(self.RandomVariable)
end
return Module
Server Script
local OOP = require(script.OOP)
local OOPClass = OOP.new()
OOPClass:PrintVariable() -- Prints 5
local Module = {}
Module.__index = Module
function Module.new()
local NewModule = setmetatable({}, Module)
NewModule.RandomVariable = 5
return NewModule
end
function Module:IncrementAttribute(InstanceLocation, AttributeName, Incremented)
InstanceLocation:SetAttribute(AttributeName, InstanceLocation:GetAttribute(AttributeName) + Incremented)
end
The .new() function is made to make a âsubclassâ in the Module, and making a new âsubclassâ from the blueprint. Technically you can remove it, I guess.