Hey guys. I was recently doing some testing and I figured out another point where you could use the “or” keyword. (or whatever “or” is known as) However, I found out that what I was trying to do wasn’t working and instead returned an error. Any way to fix this?
local function PrintEnum(Type)
print(Enum.EasingStyle[Type] or Enum.EasingStyle.Linear)
end
PrintEnum(nil) -- Still errors even with nothing in it.
I expected it to print “Enum.EasingStyle.Linear” since the type was nil, but it returned an error instead. I’m not sure how to work around this. Huge thanks if you can help me out.
the problem is it’ll still index Enum.EasingStyle to check if the style exists and Enum.EasingStyle[nil] would give you “Attempt to index Enum.EasingStyle with nil” error
local function Launch(Target)
print("Launching", Target or "nobody", "to the moon.")
end
local Target = nil
Launch(Target)
--> Launching nobody to the moon.