I always see professional scripters using “or” while defining variables,
Why do they do this?
function CommandSystems.SystemMessage(Message, Prefix, RGBColor)
local TextChatService = game:GetService("TextChatService")
local RemoteEvent = game.ReplicatedStorage.SMessage
Prefix = Prefix or "[Server] "
RGBColor = RGBColor or Color3.fromRGB(255,255,255)
task.wait(1)
RemoteEvent:FireAllClient(Message, Prefix, RGBColor)
end
heres some example code, please explain why.
All help is appreciated
It serves as a fallback if the first variable isn’t there. Ex: if rgbcolor doesn’t exist it will use the color3.fromrgb value. It is good practice to do this if you are unsure if a variable is there and don’t want to use waitforchild.
just to add on, there’s another thing that’s similar:
local isBlueApple = true
print(isBlueApple and 'its a blue apple' or 'not blue apple') -- its a blue apple
isBlueApple = false
print(isBlueApple and 'its a blue apple' or 'not blue apple') -- not blue apple
i don’t know why i chose blue apples for my explanation lol.
it’s just a shorter way of saying
if isBlueApple then
---blah blah
else
--not blue apple
end
but personally i like the second one better because its more readable imo.