AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   General Question (https://forums.alliedmods.net/showthread.php?t=184505)

mottzi 05-05-2012 21:30

General Question
 
Hi guys,

I always wondered:

When I have something like this:

PHP Code:

if(g_Mode && cs_get_user_team(i)) { ... } 

When g_Mode isnt True, will this scirpt continue with cs_get_user_team(), or will it just skip it?

So: Is it bether to do:
PHP Code:

if(g_Mode && cs_get_user_team(i)) { ... } 

or
PHP Code:

if(g_Mode)
{
   if(
cs_get_user_team(i))
   { ... }



GordonFreeman (RU) 05-05-2012 23:12

Re: General Question
 
you try to filtre "is user spectated or unassigned team"?
cs_get_user_team return team index
if teamindex>0 then it will be true

fysiks 05-06-2012 02:18

Re: General Question
 
I asked this before and IIRC, execution does not continue across an AND if the first condition is false. You could try to find my post and see what the answer was for sure.

You could even test it. Change "i" to an invalid player and run the code with g_mode = 0. If you get an error then it does execute, if no error then it doesn't execute.

Quote:

Originally Posted by GordonFreeman (RU) (Post 1703094)
you try to filtre "is user spectated or unassigned team"?
cs_get_user_team return team index
if teamindex>0 then it will be true

Nothing you said has anything to do with his question.

ProIcons 05-06-2012 04:49

Re: General Question
 
(Operation1 && Operation2) | True && False = Does Not pass
(Operation1 && Operation2) | False && True = Does Not Pass
(Operation1 && Operation2) | False && False = Does Not Pass
(Operation1 && Operation2) | True && True = Pass.

(Operation1 || Operation2) | True || False = Pass
(Operation1 || Operation2) | False || True = Pass
(Operation1 || Operation2) | False || False = Does Not Pass
(Operation1 || Operation2) | True || True = Pass.

ConnorMcLeod 05-06-2012 05:13

Re: General Question
 
Quote:

Originally Posted by ProIcons (Post 1703251)
(Operation1 && Operation2) | True && False = Does Not pass
(Operation1 && Operation2) | False && True = Does Not Pass
(Operation1 && Operation2) | False && False = Does Not Pass
(Operation1 && Operation2) | True && True = Pass.

(Operation1 || Operation2) | True || False = Pass
(Operation1 || Operation2) | False || True = Pass
(Operation1 || Operation2) | False || False = Does Not Pass
(Operation1 || Operation2) | True || True = Pass.

It is not his question.

Fysiks is right, on a && check, if 1st check is false, other ones are not checked, on a || check, if 1st condition is true, other ones are not checked.
That's why it's better to put fast checks (vars checks) before checks that imply natives calls or lot of compute.

mottzi 05-06-2012 12:21

Re: General Question
 
Thank you fysiks and Connor :)

Btw: The Post fysiks was talking about: http://forums.alliedmods.net/showthread.php?t=85522


All times are GMT -4. The time now is 00:24.

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