Hi! As a small project I made a function that converts a string into a TweenInfo. It supports all parameters, you can enter as many or as few as you want (as long as they are in order), and it supports decimals. It works perfectly fine from my testing, but I’d like to know if I can clean it up at all since it’s a lot of repeated code. Thanks
Function:
local styles = {
["ba"] = Enum.EasingStyle.Back,
["bo"] = Enum.EasingStyle.Bounce,
["ci"] = Enum.EasingStyle.Circular,
["cu"] = Enum.EasingStyle.Cubic,
["el"] = Enum.EasingStyle.Elastic,
["ex"] = Enum.EasingStyle.Exponential,
["li"] = Enum.EasingStyle.Linear,
["q1"] = Enum.EasingStyle.Quad,
["q2"] = Enum.EasingStyle.Quart,
["q3"] = Enum.EasingStyle.Quint,
["si"] = Enum.EasingStyle.Sine
}
local directions = {
["i"] = Enum.EasingDirection.In,
["o"] = Enum.EasingDirection.Out,
["io"] = Enum.EasingDirection.InOut
}
local time = string.match(str, "^%d+") or ""
str = string.gsub(str, time, "", 1)
if string.find(str, "^%.") then
local timeDecimal = string.match(str, "^%.%d+")
time = time .. timeDecimal
str = string.gsub(str, timeDecimal, "", 1)
end
local style = string.match(str, "^%a%w") or ""
str = string.gsub(str, style, "")
local direction = string.match(str, "^%a+") or ""
str = string.gsub(str, direction, "")
local repeatCount = string.match(str, "^%d+") or ""
str = string.gsub(str, repeatCount, "")
local reverse = string.match(str, "^%a") or ""
str = string.gsub(str, reverse, "")
local delayTime = str
time = tonumber(time) or 1
style = styles[string.lower(style)] or Enum.EasingStyle.Quad
direction = directions[string.lower(direction)] or Enum.EasingDirection.Out
repeatCount = tonumber(repeatCount) or 0
reverse = string.lower(reverse) == "t" and true or false
delayTime = tonumber(delayTime) or 0
return TweenInfo.new(time, style, direction, repeatCount, reverse, delayTime)
Thank you!