SphereCommunity
&& operator - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: && operator (/Thread-operator)



&& operator - darksun84 - 04-03-2012 11:18 PM

Hello ,

just a quick question , is the operator && short-circuited in sphere ?


RE: && operator - dagger4k - 04-03-2012 11:31 PM

what do you mean by short circuited


RE: && operator - darksun84 - 04-03-2012 11:40 PM

Like

a = 0
b = 1
if (a != 0 && b ==1 )

If the && operator is short circuited ,the second operation (b==1 ) doesn't get evaluated because the first operation is false .
Instead , if the && operator is not short circuited , the second operation will be anyway executed even if it's useless to evaluate it .

Better explained Big Grin http://en.wikipedia.org/wiki/Short-circuit_evaluation


RE: && operator - Shaklaban - 04-04-2012 12:57 AM

i think it is not, im tested it like this:
Code:
[function short_bla]
ref1=06f82 //uid of a character
if ((<ref1.isitem>) && (<ref1.type> = t_weapon_fence)) //this line gives error, this means second statement is controlled even first one is false
  
endif



RE: && operator - ShiryuX - 04-04-2012 01:07 AM

It is not.

Code:
[function fTest]
local.testing = 0
if ( <local.testing> && <f_test> )
serv.log yay!
endif

[function f_test]
serv.log we're firing this anyway
return 1

Code:
12:06:(sphere_test.scp,19)we're firing this anyway

Got to admit something:
1. I forgot to add < > to f_test
2. Instead of return 1, I used return true.
3. Probably, this is because I got used to C++ Tongue