Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

"And" vs. "&&"

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Sat Mar 24, 2007 4:43 pm    Post subject: "And" vs. "&&" Reply with quote

I've been having a great deal of trouble debugging a script. It has an "if" block, with two states that both need to be true (or greater than zero). It used to work. Sometime during the WIP updates, it stopped working. Funny thing is, I didn't change any of the logical coding.

I tested the two values that the if statement depends on, and they both function. After a bunch of fruitless testing and modifying, I tried a remote chance and changed my "if(this, and, that)" to "if(this, &&, that)", based on something I'd read in the whatsnew.txt file. It (seems to have) worked!

Question is, why was the functionality of "and" changed...or am I completely missing what's going on? Are the other logic statements changed as well?
Back to top
View user's profile Send private message
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Sun Mar 25, 2007 7:27 am    Post subject: Re: "And" vs. "&&" Reply with quote

Mr B wrote:
I've been having a great deal of trouble debugging a script. It has an "if" block, with two states that both need to be true (or greater than zero). It used to work. Sometime during the WIP updates, it stopped working. Funny thing is, I didn't change any of the logical coding.

I tested the two values that the if statement depends on, and they both function. After a bunch of fruitless testing and modifying, I tried a remote chance and changed my "if(this, and, that)" to "if(this, &&, that)", based on something I'd read in the whatsnew.txt file. It (seems to have) worked!

Question is, why was the functionality of "and" changed...or am I completely missing what's going on? Are the other logic statements changed as well?


&& is logical.
"and" is bitwise.

In most cases, you can use either one, but in the future it is probably best to use && in conditionals, and use "and" only when manipulating bits.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Mar 26, 2007 12:43 am    Post subject: Reply with quote

The behaviour of "and" never changed. The behaviour of "&&", however, (hopefully) will before release. (It'll be made shortcut evaluating.)

At some point comparison operators like >> and == were changed to return 1 instead of -1. This is the problem you would have run into: -1 is safer in expressions using bitwise and, 1 is for people who attempt "(hero is walking(me) == true)"
_________________
"It is so great it is insanely great."


Last edited by TMC on Sun Apr 01, 2007 7:40 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Sat Mar 31, 2007 9:27 am    Post subject: Reply with quote

Okay, interesting...

But the behavior has changed -- the statement used to function with "and" but it now does not. Or so it seems. And I wasn't using any comparison operators, right?

I feel very confused.
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun Apr 01, 2007 7:43 pm    Post subject: Reply with quote

"1, and, 2" is false, '-1, and 2" is true and "1 && 2" is true.

What was the expression anyway? There must be something in it returning a boolean value.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Thu Apr 05, 2007 8:18 am    Post subject: Reply with quote

Don't remember off the top of my head. I think it was something along the line of:
Code:
if(variable, and, script)

where the script returns a value from zero to about sixty.

So why the heck did we have access only to a bitwise "and", and why was it recommended for "if" statements? That was pretty much their only use...

Incidentaly, what would I use a bitwise "and" for? Does it transpose the "ones" in a pair of numbers? (11010000,and,01100110 => 11110110)
Back to top
View user's profile Send private message
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Thu Apr 05, 2007 8:28 am    Post subject: Reply with quote

That's OR. AND returns the bits that are true in both:

11010000,and,01100110 => 01000000
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Thu Apr 05, 2007 9:03 am    Post subject: Reply with quote

Mr B wrote:
So why the heck did we have access only to a bitwise "and", and why was it recommended for "if" statements? That was pretty much their only use...


Because QuickBasic only had bitwise AND and OR operators. I was so used to dealing with them, that it never occured to me (at the time when I was first creating Plotscripting) that logical AND and OR operators were useful.

IIRC, C and C++ both over-use bitwise operators as logic operators also.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Thu Apr 05, 2007 9:43 am    Post subject: Reply with quote

Close, but the logical operators are the common ones in C-derivative languages. (&&/|| is logical, &/| is bitwise.)
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Thu Apr 05, 2007 11:12 am    Post subject: Reply with quote

Moogle1 wrote:
Close, but the logical operators are the common ones in C-derivative languages. (&&/|| is logical, &/| is bitwise.)


I stand corrected. Maybe it was just my crazy C teacher telling us all to use & when we should have been using &&
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Fri Apr 06, 2007 11:19 am    Post subject: Reply with quote

Moogle1 wrote:
That's OR. AND returns the bits that are true in both:

11010000,and,01100110 => 01000000

Ah! The shame! Don't tell anyone I did that...

This is pretty interesting, and probably explains those few haunting oddnesses that I could never find.

So, what would constitute a "true" in the context of a bitwise AND? One or more "on" bits being shared between the two values?

So...the reason that "-1, and, 2" is true is because the "-1" has all of its bits turned on, and the two has its second-to-least-significant-bit turned on?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group