Can you Define a Variable as Boolean?
BlitzMax Forums/BlitzMax Beginners Area/Can you Define a Variable as Boolean?
| ||
Did i miss something or you cannot do it in blitz max Local Bit:Boolean |
| ||
I don't think you can, looking through the manual. A Byte variable is the nearest thing. |
| ||
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 |
| ||
Use the "SuperStrict" mode for your code compilation to assist in finding such errors. |
| ||
ok tnx for the effort |
| ||
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…?" |
| ||
sure brucey. that i know.. cheers |
| ||
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 IntType 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 |
| ||
@TomToad Nice and smart way. tahnks! |