Hi there! I just created a module that allows you verify the parameters of a remote instance by simplifying the logic involved. When using remote instances you have to validate the arguments they are called with on the server or client before processing them to prevent potentials error from being generated within your code, which can result in some lengthy and messy if statements (depending on the number of expected parameters). Also, in some cases depending on the parameters received you may want to do different things, my module helps to abstract such functionality.
Model
Pastebin
API
RemoteRequestValidator.New() - creates a new instance
RemoteRequestValidator:AddParam() - creates a new RemoteParam Object for which the sanity callback should be set.
RemoteRequestValidator:Validate(Params) - returns true if all the parameters pass their respective sanity check.
Simple Tutorial
local RemoteRequestValidator = --Require the module
local ExampleRemoteEvent = --a link to some remote event
--[[
For this example we expect the remote event to receive three parameters
the first should be a String, the second should be a base part and the
third one should be a table.
]]--
--Creating the Validator:
local ExampleRemoteValidator = RemoteRequestValidator.New()
--Adding the parameters and setting the sanity callback
--The parameters should be added in the same manner they will be processed
--Adding a check for the first expected parameter, a string
ExampleRemoteValidator:AddParam():SetSanityCallback(function(Value)
return (Value) and (typeof(Value) == "string")
end)
--Adding a check for the second expected parameter, a base part
ExampleRemoteValidator:AddParam():SetSanityCallback(function(Value)
return (Value) and (typeof(Value) == "instance") and (Value:IsA("BasePart"))
end)
--Adding a check for the third expected parameter, a table
ExampleRemoteValidator:AddParam():SetSanityCallback(function(Value)
return (Value) and (typeof(Value) == "table")
end)
--Then when connecting the remote event we can simply do
ExampleRemoteEvent.OnServerEvent:Connect(function(Player, SomeString, SomePart, SomeTable)
if (ExampleRemoteValidator:Validate(SomeString, SomePart, SomeTable)) then
--checks passed
end
end)
--[[
and you could also easily add some additional sanity checks to the sanity callback function,
this is just a simple example to explain the api.
]]--
He doesn’t really need to do that—it comes with basic understanding of Roblox scripting that you should validate data sent from RemoteEvents, and this library does that. Not every community resource is an ad encouraging people to use it, it’s just a resource should you want to.
Hello, I would recommend utilizing GitHub over Pastebin as it’s one link vs how ever many scripts you have. Furthermore we can see revision history allowing people to make informed decisions on whether or not to update their version of your script.
It should also be noted that you do not seem to include the “RemoteParam” module in your source code links. Hopefully you decide to look into GitHub!
Thank you for the feedback, I do use github so I will update the post with a link to that as well, and the RemoteParam is located at the bottom of the pastebin, but I know its confusing will definitely update later.
I really don’t see the point of it. Not to offend or anything. But I don’t see how this is more streamlined when you can do it in the Connect function with #args amount of if/elseif statements. This module is literally just those if statements but in functions. Here is your example if a normal person would do it:
local event = script.Parent
event.OnServerEvent:Connect(function(plr, string, part, table)
if typeof(string) ~= "string" then return
elseif typeof(part) ~= "instance" and not part:IsA("BasePart") then return
elseif typeof(table) ~= "table" then return end
-- do your code
end)
I did not like how messy such if statements looked that’s why I create the module, plus my version makes it more readable for me by just combining such statements into one compound statement (I’m also not a huge fan of the if not then return pattern, i find it much easier to read if this then do), and I thought a few other persons may like the idea, but I get its not for everyone. Plus that example was just a simple use case, It can become more useful when needing to perform a lot of sanity checks on the parameters, with my way the module helps to abstract that functionality from the remote connection.