Raised This Month: $7 Target: $400
 1% 

[TUT/INFO] Condition operator aka ? and :


Post New Thread Reply   
 
Thread Tools Display Modes
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 11-01-2008 , 22:11   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #21

In Pawn, there's no such thing as a bool. The "bool" tag doesn't save any extra space or reduce any amount of logical operations. Your code requires additional, useless instructions and is a bad example for people who are learning.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 11-01-2008 , 22:39   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #22

Quote:
Originally Posted by Hawk552 View Post
In Pawn, there's no such thing as a bool. The "bool" tag doesn't save any extra space or reduce any amount of logical operations. Your code requires additional, useless instructions and is a bad example for people who are learning.
This is only true because PLUGIN_CONTINUE and PLUGIN_HANDLED correspond to 0 and 1. For other values, like FMRES_*, they may not. In this special case, it's easier to do as you stated. However, in others, this solution maybe cleaner than an if() statement.
__________________

Community / No support through PM
danielkza is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 11-01-2008 , 23:43   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #23

Quote:
Originally Posted by danielkza View Post
This is only true because PLUGIN_CONTINUE and PLUGIN_HANDLED correspond to 0 and 1. For other values, like FMRES_*, they may not. In this special case, it's easier to do as you stated. However, in others, this solution maybe cleaner than an if() statement.
I never said this would work in other cases. It works in this one and reduces instructions while not making it any more confusing, so there's no reason not to do it this way.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
jaaaalot
Senior Member
Join Date: Oct 2008
Old 11-16-2008 , 11:22   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #24

PHP Code:
new bm str_to_num(arg)
 
 if(
bm == 0)
 {
  if(
get_pcvar_num(quiet) == 2)
  {
  
unpause("ac","hnk_bannedmaps.amxx")
  } 
  else
  {
   new 
name[32]
   
get_user_name(id,name,31)
   
unpause("ac""hnk_bannedmaps.amxx")
   
ColorChat(0,RED,"^x04[hnk]^x03 %s :^x01 enabled bannedmaps",get_pcvar_num(quiet) == name "ADMIN")
  }
 } 
work like this too?
jaaaalot is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 11-16-2008 , 11:29   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #25

Quote:
Originally Posted by jaaaalot View Post
PHP Code:
new bm str_to_num(arg)
 
 if(
bm == 0)
 {
  if(
get_pcvar_num(quiet) == 2)
  {
  
unpause("ac","hnk_bannedmaps.amxx")
  } 
  else
  {
   new 
name[32]
   
get_user_name(id,name,31)
   
unpause("ac""hnk_bannedmaps.amxx")
   
ColorChat(0,RED,"^x04[hnk]^x03 %s :^x01 enabled bannedmaps",get_pcvar_num(quiet) == name "ADMIN")
  }
 } 
work like this too?
You got the idea. The main use of the ternary operator is changing arguments passed to the function without writing the function+arguments two or more times.
__________________

Community / No support through PM
danielkza is offline
Grovliom
Member
Join Date: Mar 2020
Location: somewhere in Serbia
Old 04-12-2020 , 13:55   Re: [TUT/INFO] Condition operator aka ? and :
Reply With Quote #26

Amazing tutorial
Grovliom is offline
Reply


Thread Tools
Display Modes

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 07:44.


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