Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request / Listing] [Blitz Max] Bool's, anyone?  (Read 1876 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] [Blitz Max] Bool's, anyone?
« on: June 27, 2006, 11:44:09 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 221
I'm disappointed that Blitz Max doesn't have a bool data type (AFAIK) and I was hoping I could get some code that defines one. I wish I could do it myself, because it would be a good learning experience, but I have no friggin' idea how. :D Someone please help.
« Last Edit: March 18, 2012, 06:56:53 am by Niek »
Logged
Re: [Blitz Max] Bool's, anyone?
« Reply #1 on: June 28, 2006, 06:08:01 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Bool's, I assume you mean Booleans, have either one value, or not. Perhaps have them as Integers or Strings, and have the,m as "1" or 1 for true, and 0 or "0" for false. So, in terms of what I see, for example:

Code: [Select]
bool BoolTest; //define BoolTest as Boolean

BoolTest=true; //set BoolTest to true, aka 1

if (BoolTest) //if BoolTest is true, aka 1
{
write("True"); //use predefined function write to produce text True
}
else
{
write("False"); // if it isnt true, it is always FALSE.
}

is the same as

Code: [Select]
int BoolTest; //define BoolTest as Integer

BoolTest=1; //set BoolTest to 1

if (BoolTest=1) //etc as shown above.
{
write("True");
}
else
{
write("False");
}

Im probably wrong, since I'd expect BMax to have Booleans.
« Last Edit: June 28, 2006, 06:12:43 am by AoDC »
Logged
the a o d c
Re: [Blitz Max] Bool's, anyone?
« Reply #2 on: June 28, 2006, 07:59:31 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Basic didn't have booleans and thus being hybrid between basic and C it dosen't either, though if you really are desperate you can use a bit-mask or just limit the value of an int with Min and Max, booleans really are not neccessary, only for lazy people :P
Logged
Re: [Blitz Max] Bool's, anyone?
« Reply #3 on: June 28, 2006, 09:30:42 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
booleans really are not neccessary, only for lazy people :P

TAKE THAT BACK YOU MONSTER! *cries*

And didnt basic have Booleans? Wow, talk about lame :P
Logged
the a o d c
Re: [Blitz Max] Bool's, anyone?
« Reply #4 on: June 28, 2006, 09:39:56 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Well you see booleans are actually the same size as a byte, so its rather pointless having 2 datatypes of the same size when they can do exactly the same thing, the only different is a boolean is limited to 1 and 0.
Logged
Re: [Blitz Max] Bool's, anyone?
« Reply #5 on: June 28, 2006, 10:15:28 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
You should have been around when C was cooked up.
Logged
the a o d c

Ben

Re: [Blitz Max] Bool's, anyone?
« Reply #6 on: June 28, 2006, 10:38:59 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
It quite surprised me when I found out that a boolean covered an entire byte instead of just a bit. But then nothing can cover anything in bits, only bytes...

Yeh anyway.

If you have the "char" or single byte thing in Blitz, use that.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion

aab

^ Evolved from a Hobbit
Re: [Blitz Max] Bool's, anyone?
« Reply #7 on: June 28, 2006, 12:35:10 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 992
Booleans and their nessecity to cast can prevent some silly mistakes in some languages, and also give an abstraction into what they are used for.
Some languages enforce that if statements only accept booleans; If C++ did this (which it doesnt) then an accident like if(a=b) instead of if(a==b) would be an error. But C++ has built in demotion to booleans (ie an integer casts to a bool in an if automatically) which gives the impression that 0 is false and anything else is true, but really, 0 is false, 1 is true and everything else is just cast to 1 in the demotion ... This leads to silly and pointless threads like : http://www.blitzbasic.com/Community/posts.php?topic=60871
meh.

bools are just logical representations: If you think about Object orientation, the point is to be able to think about things as they actually are, in as intuitive a way as possible. Booleans are just that, for things which are either true, or false.

C never had bools for like 28 years; If you want you could do what they used to do for bools; include a file that defined a constant thats TRUE, and one thats FALSE ... But really ... well ... there'd be no casting.

I dont know if you can overload casting operators in Blitz objects, and even then it'd be quite inefficient anyway, but you could always write a class that emulates booleans by changing to either 0 or 1 during its assignment methods, or by overloading comparisons to check that their either both 0 or both non zero otherwise return false.

Logged




I ♥ Sol
.... I ♥ Sol ? wtf how long has that been there? >_> *rrrrrrrrar*
  • MySpace
Re: [Blitz Max] Bool's, anyone?
« Reply #8 on: June 28, 2006, 03:03:14 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 221
Bool's take up a whole byte? I thought it was just one bit! That really does seem pointless now that I think about it. I guess I'll just use byte's then.
Logged
Re: [Blitz Max] Bool's, anyone?
« Reply #9 on: June 28, 2006, 03:08:11 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Bool's take up a whole byte? I thought it was just one bit! That really does seem pointless now that I think about it. I guess I'll just use byte's then.

Yeh common misconception, but because of the way data is stored the minimum data-type size is 1 byte, if you want to set specific bits though, you can create a bitmask eg.

Code: [Select]
SuperStrict

Const BIT1:Int = 1
Const BIT2:Int = 2
Const BIT3:Int = 4
Const BIT4:Int = 8

Local BitMask:Int = BIT1|BIT3

If BitMask & BIT1
Print "Bit 1 set"
Else
Print "Bit 1 not set"
EndIf

If BitMask & BIT2
Print "Bit 2 set"
Else
Print "Bit 2 not set"
EndIf

If BitMask & BIT3
Print "Bit 3 set"
Else
Print "Bit 3 not set"
EndIf

If BitMask & BIT4
Print "Bit 4 set"
Else
Print "Bit 4 not set"
EndIf

Quite handy for passing large amounts of options to a function in 1 parameter :P.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.046 seconds with 57 queries.

anything