Boolean
Now you are going to get a little knowledge that you always wanted, but people were to smart to tell you.
I know at first I told you that a Boolean is a liar or a truth teller, but that was to get you to remember what values it could have, now you get the good stuff.
Everything you see on your computer, and everything that runs your computer functions by a type of code. And some of you have heard of it, it is called Binary. Maybe you have seen something like this:
011010101001110000010101010010101001001010001111110010100000101001101010101101111010111010100000010100101111001010100101
Ha!
That isn’t real binary, but I just wanted to stun you a bit. Now, this stuff is supposed to run your computer, and it is this stuff that turns electricity into computer software.
I had always wondered how you get all this stuff that a computer can do, just from electricity, I mean, electricity doesn’t have a brain. How do you take electricity and make it move a robot move? Well, this is what binary does.
These two numbers, ‘0’ and ‘1’ mean something:
0 means off
1 means on
That is the big secret!
But the Boolean does it this way:
0 means false
1 means true
Binary takes electric signals and changes them into something the computer can read.
This is how it works:
Electricity flows through a pipe, and if you grab the pipe, the electricity flows through you, and the flow of the electricity through the pipe is stops (not always). What you did is you acted as a resistor. A resistor is something that stops the flow. False is a resistor, and true allows the flow.
So, it is like ‘true’ allows the script to flow, and ‘false’ resists the script (makes it not flow).
So, when you see:
var theBlocker:Boolean = false;
You know that ‘theBlocker’ is blocking the flow of the script (because it is false).
People use Boolean in games all the time.
A Boolean is like a switch (Lights on! Lights off!).
Remember this.
This is how you make a Boolean actor(variable):
var lightSwitchOn:Boolean=true;
var lightSwitchOff:Boolean=false;
Then we can even use the conditionals to get stuff going:
if(lightSwitchOn){do something}
else if(lightSwitchOff){do something else};
This is how you would start a game:
var gameStarted:Boolean=false;
So, at first the ‘gameStarted’ variable is off. Then you say:
if(gameStarted){do something};
Remember, it’s like saying, “if lightSwtich is off.”
Here is a good example of the use of Boolean:
var box;
box.visible=true;
‘visible’ is a property of ‘box’ . ‘visible’ also has a Boolean value. If visible is true, the box can be seen (lights on!), and if it is false the box cannot be seen (lights off!).
Here is proof that ‘1’ is ‘true’:
var myBoolean:Boolean = true;
var toAnInteger:int = int(myBoolean);
trace(myInteger);
// 1
This traces the myBoolean Boolean as an integer, rather than a Boolean value. Got that?
var myBoolean:Boolean = true;
var toaNumber:Number = Number(myBoolean);
trace(myInteger);
//1
Does the same thing