Sorry, This Post Is Currently Under Maintenance. - KingBlueDash
You might want to make a documentation for this. I don’t understand some of your functions, or their use cases.
Plus, it would be nice to know what you can actually do with it before getting it.
Best regards,
Pinker
yeah, your right, i’ll make one right now, thanks.
i’m actually gonna do extensive documentation for this, but i’ll hopefully finish it later tonight, as i’m heading to bed, thanks again for the suggestion.
We love doing stuff to be spiteful!!!
I don’t see anything useful about these functions. Appreciate the effort though.
The code so you can read it from here:
local usefulFunctions = {}
usefulFunctions.__index = usefulFunctions
local function doesExists(passedType, assumedType)
if passedType then
if assumedType then
if typeof(passedType) == assumedType then
return true
else
return false
end
else
return true
end
else
return false
end
end
local functions = {
doesExists = function(tab)
if doesExists(tab, "table") and doesExists(tab[1]) then
if doesExists(tab[2]) then
return(doesExists(tab[1], tab[2]))
end
else
return(doesExists(tab[1]))
end
end;
getCertainAncestor = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "Instance") then
local temp = tab[1]
if doesExists(tab[2], "number") then
local interval = 0
repeat temp = temp.Parent; interval += 1 until interval == tab[2] or temp.Parent == workspace
print("At "..interval, "- ("..temp:GetFullName()..")")
else
repeat temp = temp.Parent until temp.Parent == workspace
end
return temp
end
end;
getObjectsWithName = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "string") then
local objTab = {}
local temp
if doesExists(tab[4], "string") and tab[4] == ":IsA" then
temp = tab[4]
end
if doesExists(tab[3], "string") and
tab[3] == ":GetDescendants()" or tab[3] == "GetDescendants()" or tab[3] == "GetDescendants"
or tab[3] == ":GetChildren()" or tab[3] == "GetChildren()" or tab[3] == "GetChildren" then
for _, i in pairs(tab[2][tab[3]]()) do
if temp then
if i:IsA(tab[1]) then
table.insert(objTab, i)
end
else
if i.Name == tab[1] then
table.insert(objTab, i)
end
end
end
end
return objTab
end
end;
getPlayerInfo = function(tab)
if doesExists(tab, "table") then
if doesExists(tab[1], "Instance") and tab[1]:IsA("Player") then
local char = tab[1].Character or tab[1].CharacterAdded:Wait()
if char:FindFirstChild("Humanoid") and char:FindFirstChild("HumanoidRootPart") then
local hum = char:FindFirstChild("Humanoid")
local humRootPart = char:FindFirstChild("HumanoidRootPart")
local infoTab = {
["char"] = char,
["hum"] = hum,
["humRootPart"] = humRootPart,
["userId"] = tab[1].UserId,
}
return infoTab
end
end
end
end;
setValuesToValue = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "table") and doesExists(tab[2]) then
for i = 1, #tab[1] do
if doesExists(tab[1][i], "Instance") and tab[1][i]:IsA("ValueBase") then
if doesExists(tab[2], "number") and tab[1][i]:IsA("IntValue") and tab[2] % 1 == 0
or tab[1][i]:IsA("NumberValue")
or doesExists(tab[2], "boolean") and tab[1][i]:IsA("BoolValue")
or doesExists(tab[2], "string") and tab[1][i]:IsA("StringValue") then
tab[1][i] = tab[2]
end
end
end
end
end;
removeAttribute = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "Instance")
and doesExists(tab[2], "string")and doesExists(tab[1]:GetAttribute(tab[2])) then
tab[1]:SetAttribute(tab[2], nil)
end
end;
addTagToObjects = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "table")
and doesExists(tab, "string") and doesExists(tab[3], "string") then
for i = 1, #tab[1] do
if doesExists(tab[1][i], "Instance") then
if tab[3] == ":AddTag()" or tab[3] == ":AddTag" or tab[3] == "AddTag" then
tab[1][i]:AddTag(tab[2])
end
if tab[3] == ":RemoveTag()" or tab[3] == ":RemoveTag" or tab[3] == "RemoveTag" then
tab[1][i]:RemoveTag(tab[2])
end
end
end
end
end;
setProperties = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "Instance") and doesExists(tab[2], "table") then
for property, value in pairs(tab[2]) do
if doesExists(tab[1][property], typeof(value)) then
tab[1][property] = value
end
end
end
end;
hasProperty = function(object, propertyName)
local success, _ = pcall(function()
object[propertyName] = object[propertyName]
end)
return success
end;
vector3Multiplication = function(vector3, value, axes, decimals)
local function round(number, decimals)
return string.format("%."..decimals.."f", number)
end
local newVector3 = vector3 + Vector3.one * value
if axes then
if decimals then
return round(newVector3[axes], decimals)
else
return newVector3[axes]
end
else
if decimals then
return Vector3.new(
round(newVector3.X, decimals),
round(newVector3.Y, decimals),
round(newVector3.Z, decimals)
)
else
print(newVector3.X..", "..newVector3.Y..", "..newVector3.Z)
end
end
return newVector3
end;
caseString = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "string") and doesExists(tab[2], "string") then
local temp
if tab[2] == "TitleCase" then
temp = tab[1]
:gsub("^(.)", function(c) return c:upper() end):gsub("(%s.)", function(c) return c:upper() end)
elseif tab[2] == "camelCase" or tab[2] == "PascalCase" then
local a
if tab[1]:find(" ") then
a = tab[1]:lower():split(" ")
elseif tab[1]:find("-") then
a = tab[1]:lower():split("-")
elseif tab[1]:find("_") then
a = tab[1]:lower():split("_")
end
if a then
local b = {}
for i = 1, #a do
if tab[2] == "camelCase" and i > 1 then
table.insert(b, a[i]:sub(1,1):upper()..a[i]:sub(2, #a[i]):lower())
elseif tab[2] == "PascalCase" then
table.insert(b, a[i]:sub(1,1):upper()..a[i]:sub(2, #a[i]):lower())
end
end
local c = table.concat(b, "")
return c
end
elseif tab[2] == "snake_case" or tab[2] == "LOUD_SNAKE_CASE" then
local a
if tab[1]:find(" ") then
a = tab[1]:upper():split(" ")
elseif tab[1]:find("-") then
a = tab[1]:upper():split("-")
end
if a then
local b = {}
for i = 1, #a do
table.insert(b, a[i].."_")
end
local c = table.concat(b, "")
if tab[2] == "snake_case" then
return c:sub(1 ,#c - 1):lower()
elseif tab[2] == "LOUD_SNAKE_CASE" then
return c:sub(1 ,#c - 1):upper()
end
end
end
return tab[1]
end
end;
color3ToRGB = function(tab)
if doesExists(tab, "table") and doesExists(tab[1], "Color3") then
return tab[1].R*255, tab[1].G*255, tab[1].B*255
end
end;
}
function usefulFunctions.new(func, params)
if doesExists(func, "string") and doesExists(params, "table") and doesExists(functions[func]) then
return functions[func](params)
end
end
return usefulFunctions
You can simplify this using:
require(118750460868833).new(...)
Additionally, consider returning the functions
table instead, as this is much less confusing for the developer, and for the type-checker.
We need to have a talk about functions. This is how you define and use them:
local function hello(text) -- 'hello' is the function. 'text' is the parameter.
print("Hello!", text) -- this is the function code
end
hello("My name is avocado.") -- here's the code calling the function, and filling the parameter with 'My name is avocado.'
--[[ Output:
Hello! My name is avocado.
]]
Parameters may be called anything and be set to anything. You don’t always need them, either. However, here’s how you’re using them:
local function hello(tab)
if type(tab) == "table" and type(tab[1]) == "string" then
print("Hello!", text)
end
end
hello {"My name is avocado."}
You may have accidently learned to call functions with braces (curly brackets), and not parathesis. When you call a function with braces, it’s the same as:
hello({"My name is avocado."})
-- is the same as
hello {"My name is avocado."}
This functionality can be very helpful, but not in your case. You should stick to using parathesis for now, and using parameters properly!
Now that you know how to use functions properly, are your functions useful? After you simplify them, they turn into only a few lines of code. This is very easy for us to code ourselves, but it could still be helpful for you to wrap them in a function. But it may not classify as a resource when it is this simple…!
Don’t worry, I’ve had this programming phase too. Have fun!
thanks, yeah these are mostly made for certain times where you’d need a specific function, but there not really necessary most times.
yeah, honestly, i just wanted to make this module as a joke, and wanted to see how much i could edge-case a script, it’s nothing too serious honestly, just a basic module while i work on my other passion projects, but i do admit it’s pretty useless lol, and thanks for the function teach, though i’ve learned how to use them a fairly well already.
also, this doesn’t work as that id refers to the model asset itself, which is why i had to require like i did lol.
i don’t have enough time to finish up documentation, but i have cleaned up the module, .new
has been removed and the functions can be called just using the module now, i’ve also lowered the line count from around 353+ to 189 lines! (don’t look at the code some of it is horrifying the way i mushed some of them together.)
I fail to understand the purpose of any of these functions.
yeah, they don’t really have one, this is just a goofy little side-project, until i release my bigger ones.
Update
I have removed the "UsefulFunctions" module entirely, as it was useless and a waste of time, which isn't something that sits right with me, especially to give out to the community, so this post will instead focus on showcasing a list of functions users may find useful, feel free to give function suggestions too.
I will also be removing any functions based on the ones in @Krant19worlddv’s plugin as per his request, thank you for reading, hope you have a good day or night.
- KingBlueDash