Raised This Month: $51 Target: $400
 12% 

!! operator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 03-28-2017 , 12:15   !! operator
Reply With Quote #1

What's mean the "!!" operator?
KiLLeR. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-28-2017 , 12:32   Re: !! operator
Reply With Quote #2

It's not a single operator, but negation operator "!" being done twice. You would want to use that when you want to coerce a cell into a boolean, following the rule that 0 = false, anything else = true.
Code:
!!(0) == false
!!(1) == true
!!(42) == true
!!(-69) == true
This way you are making sure that your boolean is either "true" or "false" and not bool:420 for example. That's good because some people prefer to do "if(variable == true)" instead of "if(variable)", which won't give correct results if you don't "normalize" your boolean value.

Last edited by klippy; 03-28-2017 at 12:56.
klippy is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 03-28-2017 , 13:07   Re: !! operator
Reply With Quote #3

So it will return always 0 or 1?

Thanks you! ;p
KiLLeR. is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-28-2017 , 13:20   Re: !! operator
Reply With Quote #4

You can also do "!= 0" to cast integer to bool.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-28-2017 , 15:03   Re: !! operator
Reply With Quote #5

PHP Code:
!(g_admin[id]) 
It means if the user is not Admin

PHP Code:
!!(g_admin[id]) 
It means If is user Admin

It just mean the opposite. Am I right?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-28-2017 at 15:04.
EFFx is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 03-28-2017 , 18:52   Re: !! operator
Reply With Quote #6

PHP Code:
!!(g_admin[id]) 
As far as i understood it means that will return 0 if is 0 and 1 if is anything different from 0. This is a way to cast integer variable to bool variable.
KiLLeR. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-28-2017 , 20:23   Re: !! operator
Reply With Quote #7

Quote:
Originally Posted by EFFx View Post
PHP Code:
!(g_admin[id]) 
It means if the user is not Admin

PHP Code:
!!(g_admin[id]) 
It means If is user Admin

It just mean the opposite. Am I right?
That entirely depends on what g_admin[id] contains. If it is user flags then no, that will not work. You should always use is_user_admin() if you want to know if they are an admin (unless, of course, you fully understand how flags work and you need something different than is_user_admin() provides).
__________________

Last edited by fysiks; 03-28-2017 at 20:24.
fysiks is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-28-2017 , 20:47   Re: !! operator
Reply With Quote #8

Well, before I readed that post I tested if it works and got what you said. It was just an example for explain what I understood. Guess it works only with intergers and booleans.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-28-2017 at 20:48.
EFFx is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-28-2017 , 21:24   Re: !! operator
Reply With Quote #9

Quote:
Originally Posted by EFFx View Post
Well, before I readed that post I tested if it works and got what you said. It was just an example for explain what I understood. Guess it works only with intergers and booleans.
With float too.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-28-2017 , 21:29   Re: !! operator
Reply With Quote #10

Using this on a boolean makes absolutely no sense since it's a double negative and will always return the original value. It's only relevant if you are trying to convert a non-boolean to a boolean value.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:21.


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