How would I make a custom function (for example part:GetProperties())?
Like this:
local examplepart = workspace.examplepart
examplepart:GetProperties() -- returns a table with all properties?
How would I make a custom function (for example part:GetProperties())?
Like this:
local examplepart = workspace.examplepart
examplepart:GetProperties() -- returns a table with all properties?
It’s kinda complicated, you probably have to use an API but i don’t really know though, but this should help you.
Make a custom workspace object that returns custom objects each time one its children are indexed, then you can add your custom functions to those objects.
How would I do that though?
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
local HttpService = game:GetService("HttpService")
local Prefix = "https://" -- since devforum prohibts me from including https in snippets
local Instances = {}
function Instances:GetPartProperities(Part : BasePart | Instance?) : {}
local BasePartProperities = {}
local fetched, _Properities = pcall(HttpService.GetAsync, HttpService, Prefix.."pastebin.com/raw/TFSU2s5e")
if not fetched then
warn("Failed, retrying?")
task.wait(1)
return Instances:GetPartProperities(Part)
end
local PartProperities = {}
for className,Properity in HttpService:JSONDecode(_Properities) do
if className ~= "BasePart" then
continue
end
for t,v in Properity do
PartProperities[v] = Part[v]
end
end
BasePartProperities[Part.Name] = PartProperities
return BasePartProperities
end
print(Instances:GetPartProperities(workspace.Part))
This is also known as serializing.
Works, thank you very much!
This is also known as serializing.
Ohh, alright.
How would I make it so you could do variable:GetProperties()
?
If you also wanna get stuff like meshid while also getting its basepart properities you can use this
local HttpService = game:GetService("HttpService")
local Prefix = "https://" -- since devforum prohibts me from including https in snippets
local Serializedstring = "_serialized"
local Instances = {}
function Instances:GetPartProperities(Part : BasePart | Instance?, SerializeOnlyNonShared: boolean) : {}
local BasePartProperities = {}
BasePartProperities[Part.Name] = {}
BasePartProperities[Part.ClassName..Serializedstring] = {}
local fetched, _Properities = pcall(HttpService.GetAsync, HttpService, Prefix.."pastebin.com/raw/TFSU2s5e")
if not fetched then
warn("Failed, retrying?")
task.wait(1)
return Instances:GetPartProperities(Part)
end
local PartProperities = {}
local AdditionalProperities = {}
for className,Properity in HttpService:JSONDecode(_Properities) do
if not SerializeOnlyNonShared then
if className == Part.ClassName then
for t,v in Properity do
AdditionalProperities[v] = Part[v]
end
end
end
if className ~= "BasePart" then
continue
end
for t,v in Properity do
PartProperities[v] = Part[v]
end
end
BasePartProperities[Part.Name] = PartProperities
BasePartProperities[Part.ClassName.."_serialized"] = AdditionalProperities
return BasePartProperities
end
local mycoolmeshpart = workspace.MeshPart
local mycoolmeshpartanditsstuff = Instances:GetPartProperities(mycoolmeshpart)
print(mycoolmeshpartanditsstuff[mycoolmeshpart.ClassName..Serializedstring].MeshId)
Alright, thanks!
30 chaaaaaaaaars
So, I was kinda joking, as this would use OOP and be super complicated. I recommend you to stick to the solution @weakroblox35 provided. But, if you really wanna go with it just so that you can do myCoolPart:GetPartProperties()
instead of Instances:GetPartProperties(myCoolPart)
then here’s what you could probably do:
Make a module (object) called workspace that returns an empty table with its metatable set to the module. Make a separate custom base part module. Now set the workspace module’s __index
to a function that looks for the base part in workspace, and if it exists, it returns a ‘custom’ base part by using the new function in the base part module, otherwise return nil.
As for the base part module (object), let the new constructor take in only one argument: the base part. The function will return an object with the only field _realPart
set to the real base part, and set the metatable to the base part module. Then add a function to the module 'CustomBasePart:GetPartProperties()
which calls the function @weakroblox35 provided, passing self._realPart
as the first argument.
Finally, set the base part module’s __index
to a function that looks for the key in the module, and if it does not find any custom function – it assumes that it’s a Roblox property or function of the object, and returns table._realPart.key
.
If this works then you can require the module and use the ‘custom’ workspace instead of game.Workspace
, you can then index parts inside of the workspace and get a reference to the table. This allows you to index the Roblox properties, call the Roblox functions on the part AND call your :GetPartProperties()
function as it is part of the object’s metatable :)))
I can’t really understand
I think I’ll just stick to using Instances:GetPartProperties(examplepart)
.
Welcome to the functional programming gang.
abcdefghijklmnopqrstuvwxyzabc
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.