Jump to content

OR logical operator problem


JeViCo

Recommended Posts

9 minutes ago, Mahlukat said:

-- it's too short :P
local icon = getBlipIcon(blip)
if icon == 32 or icon == 35 then

-- or

icons = {
	[32] = true,
	[35] = true,
}

if icons[getBlipIcon(blip)] then

 

that's even better! Thank you ^_^

  • Thanks 1
Link to comment

Just so that you understand why it doesn't work:

getBlipIcon() == (32 or 35)

let's say that results in:

8 == (32 or 35)

in this case it's obviously false.. but look at this:

35 == (32 or 35)

that is also false.
The reason is that this:

(32 or 35)

always results in 32, because 32 is a number -> it's not a falsey value. The code never even checks what's after the or because it doesn't have to as the condition was already satisfied.
That means that the brackets will always result in 32, and

35 == 32

is obviously false.

Edited by MIKI785
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...