What is the difference between ~= and not in roblox code?
not
is a unary operation that is similar to unary minus in arithmetic:
-a is the same as 0 - a
However, it inverts a boolean value, instead of a number:
not true is false not false is true
Here could be a home-grown definition of a Not
function acting the same way not
does:
function Not(value) if value then return false; else return true; end end
It returns the opposite of what it is given (cast to a boolean).
~=
is the "not equal to" relation. For instance, since 4
and 5
are not the same, then 4 ~= 5
is true.
Because of this, not (a == b)
is the same as a ~= b
. However, not
is much more powerful, because it can be used with any expression; its usefulness comes from its ability to be compounded in other logical operations.
Here are some excerpts from my Portal code which use not:
if (noig or (not ig[pns[i]])) and ray.direction:Dot( pns[i].normal) <= 0 then if (not paused) and selected then if (k == "f" or k == "e") and not paused then
There really is not a difference, because ~= means not equal to and in the term below, it is basically saying not true or equal to.
if not game.Workspace.Name == "Workspace" then
Basically it means the same thing, just different ways of doing it.