Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

What is the difference?

Asked by 10 years ago

What is the difference between ~= and not in roblox code?

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
Ad
Log in to vote
-1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

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.

1
I have to disagree with this answer because `not` is a much more powerful and standalone construct than being an inconvenient way to say ~=. BlueTaslem 18071 — 10y

Answer this question