CesarESP
CesarESP

Reputation: 129

Why is if not var == nil not running if var is 1?

Simple piece of code, supposed to print works is not doing so. I really can't understand this. This is code:

local var = 1
if not var == nil then
    print("works")
end

Upvotes: 2

Views: 77

Answers (2)

lhf
lhf

Reputation: 72402

Operator precedence fooled you:

if not asd == nil then

is equivalent to

if (not asd) == nil then

Try

if not (asd == nil) then

Upvotes: 3

CesarESP
CesarESP

Reputation: 129

Sorry, answer was doing

local asd = 1
if asd ~= nil then
print("works")
end

I didn't even knew that ~= is a thing wow

Upvotes: 1

Related Questions