Extensions have boolean logic limitations?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC

Extensions have boolean logic limitations?

Post by Carl Lydon »

Hi,

In an extension, if I try something like:

if (x==1 or y==1){
//do something
}

The script won't load. If I get rid of the "or" and do a nested "if" statement, it works fine. Is this a known limitation?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

use || instead of or, same with and = &&
ptdgames
Posts: 39
Joined: 10 Mar 2008, 21:55

Post by ptdgames »

Also, get into the habit of doing this:

if ( (x==1) || (y==1) ) {
// do something
}

The extra () sets will make sure the compiler behaves exactly the way you want.
duncanhall
Posts: 29
Joined: 04 May 2008, 14:52
Contact:

Post by duncanhall »

I would advise the exact opposite of what ptd suggests.

The compiler is more than happy to recognise (x==1 || x==2) as two seperate conditionals, and the added parenthesis just make it harder to spot exactly what is being evaluated. I would only really include the nested parenthesis when you have multiple evaluations in each conditional.

eg:

if (( x > 3 && x < 10 ) || (x > 20 && x < 30))
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC

Thanks

Post by Carl Lydon »

Thanks for all the advice. The main thing was that my Flash compiler always recognized "and"..."or", but that Smartfox extensions might not. I'll be in the habit now of always using || or &&
Post Reply