I've seen conditional statements without any comparison before, ones that don't use equal, less than, greater than, etc. signs. I'm not sure how this works. If somebody could explain this it would be really helpful to finally understand this.
Here is an example of what I am talking about:
game.Players.PlayerAdded:connect(function(player) if player then print("New Player") end end)
In Lua, there are only two false values; everything else is considered true. This means that
if 5 then end
wiill run, and
if {} then end
will run.
The two false values are false and nil.
Assuming the variable player references a Player object...
if player then
is the same as
if player ~= nil then
Essentially, when an object is used as a condition in a conditional statement, it is treated like a "true" statement. Conversely, if the reference to the object no longer exists, then the reference will return nil. This is equivalent to a false statement.
Keep in mind that fundamentally, all conditional statements are either true statements or false statements; there's no "in-between".
Locked by Articulating
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?