Author |
Message |
Jimbo1991
|
Posted: Tue May 27, 2008 10:05 am Post subject: what is a boolean |
|
|
what exactly is a boolean? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
SNIPERDUDE
![](http://compsci.ca/v3/uploads/user_avatars/16932914504cbd0ad6ceaf1.jpg)
|
Posted: Tue May 27, 2008 10:09 am Post subject: RE:what is a boolean |
|
|
a boolean is a type of variable.
an integer (int) holds a whole number
a real number (real) hold a decimal number
a boolean hold a true/false value.
ex:
var test : boolean := true |
|
|
|
|
![](images/spacer.gif) |
isaiahk9
![](http://compsci.ca/v3/uploads/user_avatars/1465120414488e669e1f83a.jpg)
|
Posted: Tue May 27, 2008 3:18 pm Post subject: RE:what is a boolean |
|
|
Booleans are useful when you only deal with two possible outcomes.
Example -
var isp1right : boolean := true
loop
if player clicks left key, then isp1right := false, p1x -= 5
elsif player clicks right key, then isp1right := true, p1x += 5
end if
Draw (character, p1x, p1y, PicMerge)
end loop
%I used this for my fighter game - so that the character would face right and left when you press right and left. |
|
|
|
|
![](images/spacer.gif) |
Hendo
![](http://compsci.ca/v3/uploads/user_avatars/1049240745485a9912c2ba0.jpg)
|
Posted: Tue May 27, 2008 7:37 pm Post subject: RE:what is a boolean |
|
|
yeah they're very useful if you only want to execute something if the variable hold true (or not)
So something like
code: | if boolvar1 = true then
x=x+1
else
%if its not true
x=x-1 %do this instead
end if
|
|
|
|
|
|
![](images/spacer.gif) |
Reality Check
|
Posted: Tue May 27, 2008 8:20 pm Post subject: Re: what is a boolean |
|
|
It's simply a variable with only two possible states. This is ideal for checking is a certain event has been reached and whatnot and is more ideal than using any other kind of variable because it'd use less memory. |
|
|
|
|
![](images/spacer.gif) |
Mackie
![](http://compsci.ca/v3/uploads/user_avatars/217548454cee912ae1202.png)
|
Posted: Tue May 27, 2008 8:25 pm Post subject: RE:what is a boolean |
|
|
Actually a boolean is 8 bits, same as nat1 (Range of 0 - 255).
Surprising enough, I'd think it would only be 1 bit. On or off. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue May 27, 2008 8:37 pm Post subject: RE:what is a boolean |
|
|
a boolean, as a variable, is indeed 8 bits. If you want to use less memory though, you could use a nat1 as an array of 8 boolean values. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Mackie
![](http://compsci.ca/v3/uploads/user_avatars/217548454cee912ae1202.png)
|
Posted: Tue May 27, 2008 8:51 pm Post subject: RE:what is a boolean |
|
|
That is a very smart idea! I'll have to remember that. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|