Hi, so I’m wondering how should I simplify this code I have to add Data to a Table, I plan to add more to the functions, but i just want to get this out of the way if there is a better way to do this.
The first thing I did Simplify was with the if
statements where you would check for a Condition and if true, it will return an error()
:
if Condition then error("error occurred!") end
But, this would be a bit unnecessary to do,
however this can be simplified with assert()
assert(Condition, "error occurred!")
But the issue is that I would have to use assert()
everytime to check for a statement, if this there are way to simplify it so I don’t have to use that many?
I am wondering if there was a way to simplify all these assert()
functions:
function UDInfo.new(Key: string, Value: any) -- All these assert functions
assert(Key ~= nil, "Key must have a Value!")
assert(string.len(Key) > 0, "Key must not be empty!") -- I get you can use #Key but ¯\_(ツ)_/¯
assert(type(Key) == "string", "Key has to be a string!") -- might not be necessary
assert(DataKeys[Key] == nil, "Key Already exists.") -- maybe "not DataKeys[Key]?"
assert(Value ~= nil, "Value Cannot be nil")
DataKeys[Key] = Value -- I plan to add more than just this, I'm just Testing if this works
end