Jump to content

if statement == that OR that


kuwalda

Recommended Posts

organizacijuSkinList["teamPolice"] = { 280, 281 } 
if tonumber(getElementModel(thePlayer)) ~= (tonumber(organizacijuSkinList["teamPolice"][1]) or tonumber(organizacijuSkinList["teamPolice"][2])) then 

I am storing my organisations skin lists in table like shown above.

Problem is that my if statement works only for first check.

Like in simplified version, lets say player got skin 311

if 311 ~= 312 or 241

This check works only for first value (311 ~= 312), but it ignores second check (241). Why?

Link to comment

There is no need to, because this script works, but only this line bothers me.

Instead of:

if tonumber(getElementModel(thePlayer)) ~= (tonumber(organizacijuSkinList["teamMehanic"][1]) or tonumber(organizacijuSkinList["teamMehanic"][2])) then 

I could have used:

if tonumber(getElementModel(thePlayer)) ~= (tonumber(organizacijuSkinList["teamMehanic"][1]) then 
if tonumber(getElementModel(thePlayer)) ~= tonumber(organizacijuSkinList["teamMehanic"][2])) then 

But it feels wrong to me and I wanted to found out, how can I do it corectlly.

Link to comment
  • 2 weeks later...
x == y or z 

This expression will check if either of conditions "x == y" and "z" is true. If "z" is anything besides nil or false, the condition will be satisfied. It's the same as this expression:

(x == y) or (z) 

If you need to check if x is equal to either y or z, you need to make it this way:

x == y or x == z 

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...