Can you Define a Variable as Boolean?

BlitzMax Forums/BlitzMax Beginners Area/Can you Define a Variable as Boolean?

Hardcoal(Posted 2013) [#1]
Did i miss something or you cannot do it in blitz max

Local Bit:Boolean


Grisu(Posted 2013) [#2]
I don't think you can, looking through the manual.

A Byte variable is the nearest thing.


Hardcoal(Posted 2013) [#3]
yea byte is nice
but i want bit because i want it to produce error when i may mistakingly try to use it as byte


Grisu(Posted 2013) [#4]
Use the "SuperStrict" mode for your code compilation to assist in finding such errors.


Hardcoal(Posted 2013) [#5]
ok tnx for the effort


Brucey(Posted 2013) [#6]
Just use an Int. Your "Byte" variable is likely going to take up 4 bytes of space anyway, so you may as well use an Int, where zero is False and anything else is True.

Then you can do your basic truthfulness tests :
Local canJump:Int

…

If canJump Then ' True
…
End If

If Not canJump Then ' False
…
End If


Not sure how you might mistakingly use a variable for something else. Unless you call it "z" or something, rather than by a meaningful name. "Hmm, I wonder what my 'z' variable was for again…?"


Hardcoal(Posted 2013) [#7]
sure brucey.
that i know..
cheers


TomToad(Posted 2013) [#8]
Here's one way to create your own boolean type which can only be defined as BTrue or BFalse. Uncomment the last line to find out what happens when you try and define as an Int
Type Bool
End Type

Global BTrue:Bool = New Bool
Global BFalse:Bool = Null

Local Value1:Bool = BTrue
Local Value2:Bool = BFalse

If Value1
	Print "Value1 is true"
Else
	Print "Value2 is false"
End If

If Value2
	Print "Value2 is True"
Else
	Print "Value2 is false"
End If

'Local Value3:Bool = 15 'uncomment to create error



Hardcoal(Posted 2013) [#9]
@TomToad
Nice and smart way. tahnks!