Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Ytterbium on Wed 28/01/2004 16:40:02

Title: Suggestion: XOR operator
Post by: Ytterbium on Wed 28/01/2004 16:40:02
I've noticed the Or (||) operator will trigger an action in an if statement if one or both are true. I think an XOR operator, which would trigger the if statement if one but not both are true, would be very useful in scripting.
Title: Re:Suggestion: XOR operator
Post by: Proskrito on Wed 28/01/2004 17:00:47
but, you can do that easily with the actual && and || operators, cant you?... ::)
like  if ((a==1 && b==0) || (a==0 && b==1))...
Title: Re:Suggestion: XOR operator
Post by: SSH on Thu 29/01/2004 14:38:16
Easier than that: a logical XOR is the != operator...

0 != 0 gives 0
0 != 1 gives 1
1 != 0 gives 1
1 != 1 gives 0

of course, each side must be 0 or 1 for this to work.

It might be nice to have bitwise operators sometimes, though like &, | and ^
Title: Re:Suggestion: XOR operator
Post by: Scorpiorus on Thu 29/01/2004 17:49:36
QuoteIt might be nice to have bitwise operators sometimes, though like &, | and ^
There are bitwise AND and OR already, but still missing the NOT and XOR ones. :P
Title: Re:Suggestion: XOR operator
Post by: a-v-o on Thu 29/01/2004 19:04:24
For NOT you can use a simple subtraction and with it you can build a xor function:


// for 16 bit integers
#define MAXINT   2147483647

function not (int a)
{
 return MAXINT - a;
}

function xor (int a, int b)
{
 return (not ((a & b) | (not (a) & not (b))));
}



Title: Re:Suggestion: XOR operator
Post by: Pumaman on Sat 31/01/2004 14:23:33
Adding missing operators MOD, NOT and XOR is on my to-do list. Are there any other common operators that the script is missing, while we're at it?
Title: Re:Suggestion: XOR operator
Post by: Scorpiorus on Mon 16/02/2004 23:10:36
Quote from: a-v-o on Thu 29/01/2004 19:04:24
For NOT you can use a simple subtraction and with it you can build a xor function
thanks for the quick tip :)

Quote from: Pumaman on Sat 31/01/2004 14:23:33Are there any other common operators that the script is missing, while we're at it?
left/right shifting operators could come in handy provided it's not some hassle to implement those of course.
Title: Re:Suggestion: XOR operator
Post by: a-v-o on Mon 16/02/2004 23:12:56
shift 1 bit left: *2
shift 1 bit right: /2
Title: Re:Suggestion: XOR operator
Post by: Scorpiorus on Tue 17/02/2004 19:05:20
Yep, that's how I've done it so far. However, it's an arithmetical shift and I'd also like to see a logical shift (right direction with leading 0s) too. Again it can be workarounded but anyway those I'd like to suggest to be built in AGS. Would be cool to have them as operators with proper type conversion (again if it's not too much work with script engine-related code).

~Cheers