#True is only 1, not all True

Everything else that doesn't fall into one of the other PB categories.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: #True is only 1, not all True

Post by rsts »

utopiomania wrote:#TRUE is a constant defined as NOT #FALSE. True can be anything as long as it is not false, and false
can be anything as long as it is not true.

Simple as that. :roll:

Code: Select all

Define condition
condition=6
If condition = #True
  debug "Condition is #True"
EndIf

If condition  NOT #False
  debug "condition is NOT #False"
EndIf
:?:
User avatar
JackWebb
Enthusiast
Enthusiast
Posts: 109
Joined: Wed Dec 16, 2009 1:42 pm
Location: Tampa Florida

Re: #True is only 1, not all True

Post by JackWebb »

I was just thinking about this the other day while working on an IF structure. I have to agree with Mr. Gaman's original question. #False is always false it never changes. But #True is not always "true" but never false. This is what I came up with. I wonder if it will work in every case? Thanks to Idle for the tip!

Code: Select all

Macro IsTrue(v)
  v Or 0
EndMacro

Macro IsFalse(v)
  0 Not v
EndMacro

Test = 0

If IsTrue(Test)
  Debug "test is true"
EndIf

If IsFalse(Test)
  Debug "test is false"
EndIf

Jack
Make everything as simple as possible, but not simpler. ~Albert Einstein
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: #True is only 1, not all True

Post by Trond »

Why go through all of that hassle when you can do it correctly like this:

Code: Select all

Test = 0

If Test
  Debug "test is true"
EndIf

If Not Test
  Debug "test is false"
EndIf
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: #True is only 1, not all True

Post by Joakim Christiansen »

Trond wrote:Why go through all of that hassle when you can do it correctly like this:

Code: Select all

Test = 0

If Test
  Debug "test is true"
EndIf

If Not Test
  Debug "test is false"
EndIf
+1

And maybe PB should get the keywords "true" and "false" too; so people wont mistake the constant for such...
Last edited by Joakim Christiansen on Tue Jan 12, 2010 2:54 am, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
User avatar
JackWebb
Enthusiast
Enthusiast
Posts: 109
Joined: Wed Dec 16, 2009 1:42 pm
Location: Tampa Florida

Re: #True is only 1, not all True

Post by JackWebb »

Trond wrote:Why go through all of that hassle when you can do it correctly like this:

Code: Select all

Test = 0

If Test
  Debug "test is true"
EndIf

If Not Test
  Debug "test is false"
EndIf
Because pointless coding gymnastics force me to think about things I normally would not think about. Also because it helps a PureBasic noob like me gain a deeper understanding of the language. Other than that it's a good question and interesting to read everyone's reponses and code. :D

Jack
Make everything as simple as possible, but not simpler. ~Albert Einstein
Post Reply