Introduction
I lately wanted a way to add custom functions and properties to my Roblox objects without inconvenience so I created this simple project! All you need to do is insert this code above all of your scripts:
local ezWrapper = require(...) --> path here
ezWrapper:Setup()
It will then automatically wrap every instance from that point forward in a script without you having to even think about it!
Pros
- Easy to use
- Increased versatility of all instances
- Works across scripts
- Even wraps objects passed in signals like ‘DescendantAdded’
Cons
- Not as fast as regular objects, but that’s to be expected
- Doesn’t work across the client / server boundary naturally
Documentation
Instances
These methods work across all instances that come into the script’s environment.
:SetCustomProperty(‘name’,‘value’)
Arguments: string
, any (table, color, string, number, and more!)
Description: Sets a custom property for the specified instance that can now be indexed directly as a priority
Sample code:
object:SetCustomProperty("Damage",15)
print(object.Damage) --> 15
:SetFunction(‘name’,‘function’,‘methodCheck’)
Arguments: string
,function
,boolean
Description: Sets the specified method on the object, similar to the :SetCustomProperty but can check for if it’s called as a method internally
Sample code:
object:SetFunction("GetData",function(argument)
return({name = "hello",calledWith = argument})
end,true)
print(object:GetData("test")) --> {name = "hello",calledWith = "test"}
:NewSignal(‘name’)
Arguments: string
Description: Creates a custom signal that can be connected to for the object
Returns: <signal>
Sample code:
local signal = object:NewSignal("Hello")
signal:Connect(function()
print("do something cool here")
end)
object.Hello:Fire()
:GetRaw()
Arguments: <N/A>
Description: Returns the raw object instance if you need it for some reason
Returns: Instance
Sample code:
object:GetRaw()
:GetCustomProperties()
Arguments: <N/A>
Description: Returns all custom properties set as a dictionary
Sample code:
object:SetCustomProperty("test","hi")
print(object:GetCustomProperties()) --> {test = "hi"}
:GetCustomFunctions()
Arguments: <N/A>
Description: Returns all custom functions in a dictionary similar to the above
Sample code:
object:SetFunction("Get",function()
print("cool")
end)
print(object:GetCustomFunctions()) --> {Get = <function>}
Credits
Where do I get it?
- Bam! Get it here!
Disclaimers
- I made this as a learning experience and I am open to constructive criticism that’s helpful to making my code more efficient as a developer.
- I don’t expect this to work 1000% absolutely flawlessly and I expect bugs but I haven’t had any before releasing and I hope you can discover and report any to me!
Polls
- Yes
- No
0 voters
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
0 voters