Runaway
09-24-2009, 06:46 AM
Fun With Booleans:
http://img9.imageshack.us/img9/7082/booleanlogic.png (http://img9.imageshack.us/i/booleanlogic.png/)
Most of you probably know what a “Boolean” is, yet do not know exactly what it means or how it receives a true or false result. Boolean logic is the logic of operators, the logic of multiple inputs sending only one output. The average script is full of Boolean logic that most people do not even realize is, in fact, a Boolean. Enough crazy talk, let’s get down to business.
A Boolean has 6 different types of input-output procedures:
And
Or
Nand
Nor
Xor
And Xnor
These all have similar functions, but have varied outputs. Let’s start with AND.
----------------------------------------------------------------------------------------------------------------
AND – One of the most common operators, this requires both inputs to be true in order to output as true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) and
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//The script will only exit out of the procedure if, and only if, the script finds both of those colors.
----------------------------------------------------------------------------------------------------------------
OR - Also one of the more common operators, this requires at least one of the inputs to be true in order to output as true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) or
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//The script will exit out of the procedure if it finds either one of the specified colors.
----------------------------------------------------------------------------------------------------------------
NAND - Or "Not And", this is the complete opposite of AND. This outputs as true if the inputs are not all true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) nand
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds none or one of those colors, but will not exit if it finds both.
----------------------------------------------------------------------------------------------------------------
NOR - Or "Not Or", this is the complete opposite of OR. This outputs as true if both inputs are false.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) nor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if, and only if, neither of the specified colors are found.
----------------------------------------------------------------------------------------------------------------
XOR - Or "Exclusive Or", This is a special OR operator. This will output as true if the specified inputs differ from each other.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) xor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds one of the colors,
//but will not exit out if it finds neither or both of the colors.
----------------------------------------------------------------------------------------------------------------
XNOR - Or "Not Exclusive Or", This is also a special OR operator. This will output as true if the inputs are both false or both true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) xnor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds neither of those colors, but also if it finds both of them.
----------------------------------------------------------------------------------------------------------------
Those are the 6 different variables that relate to Boolean logic, and can be quite useful when scripting (maybe not XOR :p). I hope you will use some of the more unique Boolean variables now that you have more knowledge of what they do!
http://img9.imageshack.us/img9/7082/booleanlogic.png (http://img9.imageshack.us/i/booleanlogic.png/)
Most of you probably know what a “Boolean” is, yet do not know exactly what it means or how it receives a true or false result. Boolean logic is the logic of operators, the logic of multiple inputs sending only one output. The average script is full of Boolean logic that most people do not even realize is, in fact, a Boolean. Enough crazy talk, let’s get down to business.
A Boolean has 6 different types of input-output procedures:
And
Or
Nand
Nor
Xor
And Xnor
These all have similar functions, but have varied outputs. Let’s start with AND.
----------------------------------------------------------------------------------------------------------------
AND – One of the most common operators, this requires both inputs to be true in order to output as true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) and
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//The script will only exit out of the procedure if, and only if, the script finds both of those colors.
----------------------------------------------------------------------------------------------------------------
OR - Also one of the more common operators, this requires at least one of the inputs to be true in order to output as true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) or
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//The script will exit out of the procedure if it finds either one of the specified colors.
----------------------------------------------------------------------------------------------------------------
NAND - Or "Not And", this is the complete opposite of AND. This outputs as true if the inputs are not all true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) nand
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds none or one of those colors, but will not exit if it finds both.
----------------------------------------------------------------------------------------------------------------
NOR - Or "Not Or", this is the complete opposite of OR. This outputs as true if both inputs are false.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) nor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if, and only if, neither of the specified colors are found.
----------------------------------------------------------------------------------------------------------------
XOR - Or "Exclusive Or", This is a special OR operator. This will output as true if the specified inputs differ from each other.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 0 --
-- 1 ------- 0 ------ 1 --
-- 0 ------- 1 ------ 1 --
-- 1 ------- 1 ------ 0 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) xor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds one of the colors,
//but will not exit out if it finds neither or both of the colors.
----------------------------------------------------------------------------------------------------------------
XNOR - Or "Not Exclusive Or", This is also a special OR operator. This will output as true if the inputs are both false or both true.
Input 1 Input 2 Output
-- 0 ------- 0 ------ 1 --
-- 1 ------- 0 ------ 0 --
-- 0 ------- 1 ------ 0 --
-- 1 ------- 1 ------ 1 --
As an example in scar, it would be used like so:
Begin
If FindColor(x, y, 12345, x1, y1, x2, y2) xnor
FindColor(x, y, 54321, x1, y1, x2, y2) then Exit;
End;
//This script will exit out of the procedure if it finds neither of those colors, but also if it finds both of them.
----------------------------------------------------------------------------------------------------------------
Those are the 6 different variables that relate to Boolean logic, and can be quite useful when scripting (maybe not XOR :p). I hope you will use some of the more unique Boolean variables now that you have more knowledge of what they do!