JeViCo Posted May 20, 2018 Posted May 20, 2018 Hello community! Why this part of code doesn't work? getBlipIcon(blip) == (32 or 35) then i really don't want to write getBlipIcon(blip) == 32 or getBlipIcon(blip) == 35 then each time (((
Mahlukat Posted May 20, 2018 Posted May 20, 2018 (edited) -- 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 Edited May 20, 2018 by Mahlukat 1
JeViCo Posted May 20, 2018 Author Posted May 20, 2018 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 1
MIKI785 Posted May 21, 2018 Posted May 21, 2018 (edited) 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 May 21, 2018 by MIKI785 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now