AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple question about verifying values (https://forums.alliedmods.net/showthread.php?t=236330)

georgik57 03-03-2014 04:57

Simple question about verifying values
 
Is the following example
Code:

if (get_pcvar_num(pcvar) == 1 || get_pcvar_num(pcvar) == 3)
the same as
Code:

if (get_pcvar_num(pcvar) == (1 | 3))
?

Thanks in advance.

NiHiLaNTh 03-03-2014 06:00

Re: Simple question about verifying values
 
single | is bitwise OR. Probably you can do it like that:

Code:

if (1<<get_pcvar_num(pcvar) & (1<<1)|(1<<3))

georgik57 03-03-2014 06:09

Re: Simple question about verifying values
 
Quote:

Originally Posted by NiHiLaNTh (Post 2106684)
single | is bitwise OR. Probably you can do it like that:

Code:

if (1<<get_pcvar_num(pcvar) & (1<<1)|(1<<3))

Hi Nihi ^_^
Yes that works but doesn't it multiply the value with itself?
What I'm trying to do is optimize, since getting the same cvar twice in a single check is pointless.
What's the best way I could do that?

YamiKaitou 03-03-2014 11:27

Re: Simple question about verifying values
 
Your 2nd example isn't right, it doesn't work that way. Unless you are dealing with bits, you will need to do as you did in your 1st example

georgik57 03-03-2014 13:05

Re: Simple question about verifying values
 
Quote:

Originally Posted by YamiKaitou (Post 2106781)
Your 2nd example isn't right, it doesn't work that way. Unless you are dealing with bits, you will need to do as you did in your 1st example

Yes, I tested several ways of doing it and the best one seems to be creating a new variable and storing the cvar value.
Thank you.


All times are GMT -4. The time now is 05:59.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.