NOT

Blitz3D Forums/Blitz3D Programming/NOT

Rook Zimbabwe(Posted 2004) [#1]
It says in the docs you can use NOT in an IF statement... but no example

I have tried:
IF soundflag Not = 1
; and
If Soundflag Not 2

I can't get either to work.
-RZ


SabataRH(Posted 2004) [#2]
examples:

While Not Eof(f)
wend
;--------------------------------
t=True
If Not T Then RuntimeError "hey"


sswift(Posted 2004) [#3]
Generally I would only use Not when dealing with boolean values. Ie, values which are true or false.

Ie:

If Not GameOver

Where gameover can equal true or false.

In your examples, I would avoid using not. I would do this instead:

If Soundflag <> 1


Rottbott(Posted 2004) [#4]
This:
Not (SoundFlag = 1)
is the same as this:
SoundFlag <> 1


Like Sswift said, you don't really need to use Not here.


big10p(Posted 2004) [#5]
For flags that can only be set to true/false, I usually just use:

If SoundOn
  ; SoundOn=True
Else
  ; SoundOn=False
EndIf



ChrML(Posted 2004) [#6]
Someboole = Not Somebool


Inverts the boolean. If it was 1, it becomes 0, if it was 0 it becomes 1.

Usually in other programming languages, Not would also function as a way to invert an integer from positive/negative. Not 20 = -21 for example. But in Blitz it only works with booleans (1/True and 0/False).

When you say:
If something=4 Then
  blablabla...
EndIf


Something=4 is a way to get a boolean out of an equation (the equation is true? or is it false?). Saying this:
somebool=(something=4)


Then somebool will be True if something actually equals to 4, or it will be false if something does not equal. If is a quite simple operation actually. If the boolean that comes after the If (as long as we don't include And/Or which takes more booleans into count) is True, then the If section is executed, if the value is False, then eventually the Else section will be executed if it exists.

If (something=4) Then ;something=4 generates either True or False
  ...blablabla
Endif

;lets say something does equal to 4, then this would happen:
If True Then
  ...blablabla
EndIf

;causing the boolean after If to be True, and therefore it executes. If something did not equal to 4, the same thing would happen, only that False comes after If.

;And ofcourse you can add not before, as the actual If question then is:
If Not True Then
  ...blablabla
EndIf

And as you know Not True = False. Therefore in short, Not is ALWAYS before a boolan in Basic (either with a=b booleans, or True/False booleans).


Hope this helps you to understand programming better :), as I know it takes a while before you actually understand the magic behind If.

Thinking of C, the rules are the same, except that no Not is not allowed (! is used instead). Like:
if (something == 4)
{
  ...blablabla
}


There the same rules exists, if the value after If is True, then executed, and vice versa :).

If you want to use not in C, you would have to do:
if (something != 4)
{
  ...blablabla
}

//or (// are comments in C)

if !(something == 4)
{
  ...blablabla
}


Lol, that got quite an explaination, but sure it is good to know, as it really helps you to understand the logic behind programmming.


Rook Zimbabwe(Posted 2004) [#7]
It does thanks! :)


Cancerian(Posted 2004) [#8]
After briefly scanning all the posts I don't think anyone mentioned that the reason it didn't work for you is simply because you had NOT in the wrong place. In my experience NOT comes before the value check, otherwise Blitz would be thinking Not is the variable you are checking. So,,,

IF soundflag Not = 1

should read...

If NOT soundflag = 1

In english you are saying "if soundflag doesn't = 1"


GfK(Posted 2004) [#9]
After briefly scanning all the posts I don't think anyone mentioned that the reason it didn't work for you is simply because you had NOT in the wrong place.
After a brief scan, at least three people mentioned exactly that already.


_PJ_(Posted 2004) [#10]
If Not KeyDown(57)


doesn't work.
Admittedly, it's a bit of a useless one, and much better to either substitute the alternative

If KeyDown(57)

or use the GetKey$() commands etc. Just a point of note I discovered the other day.


ChrML(Posted 2004) [#11]
It's very important that you understand WHY you can't use NOT right before the =.

Read my post. It's very important that you understand how IF basically works (which you obviously don't as you wouldn't ask this question then). It makes everything simplier.


Rook Zimbabwe(Posted 2004) [#12]
Actually I DO understand how IF works... I was asying that in the DOCS it says you can use NOT with IF and there was NO EXAMPLE... I tried IF yadda NOT yoda and I tried IF yadda NOT = yoda. None worked. Cancerian and Malice were MUCh more helpful and less insulting!


jhocking(Posted 2004) [#13]
"After briefly scanning all the posts I don't think anyone mentioned that the reason it didn't work for you is simply because you had NOT in the wrong place.

After a brief scan, at least three people mentioned exactly that already."

Where? Starting from the top, alienhead didn't mention it, sswift didn't mention it, rottbott didn't, big10p didn't. Maybe Chrml did, somewhere in that dissertation. And then, oh look it's Cancerian. A couple people alluded to the point by placing it correctly in code they posted, but nobody specifically pointed it out.


Incidentally, I'm with other people here that I'd write it like this:
If Soundflag <> 2

Omitting Not and using symbols is paradoxically simpler to understand because the Not would go in a spot that reads strangely.


ChrML(Posted 2004) [#14]
@Rook Zimbabwe: Why is it insulting that I said that you obviously don't understand how IF works? Just to make that clear, the wrong explaination:

"IF just checks if the equation that comes after is right, and then it executes".

The correct explaination:

"Every equation is a boolean value (TRUE/FALSE), and IF executes the comming section if the boolean (which might be in form of a math eqation) that comes after is True. Then again, NOT is a boolean operand (explained in manual as NOT true), and not a way to write eqations, meaning NOT is just a word that inverts a boolean. Therefore NOT obviously comes before the eqation which is the boolean (switches it)."


I don't mean to be insulting in any way, but the way your original question was formulated, it told me that you obviously don't know what I explain a few posts above (the stuff about equation = boolean).

@jhocking: Yes, I agree, I would also write it <> (is test$ <> "hehe" allowed in BB?, atleast it is in most other languages I know).


_PJ_(Posted 2004) [#15]

Cancerian and Malice were MUCh more helpful


Heh thanks... but I didnt help at all, I feel - Just mentioned I had run into issues with NOT as a command.

I do agree Cancerian's post is the most to-the-point and helpful without overcomplicating matters!


ChrML(Posted 2004) [#16]
Again half a site of text written to a guy who don't even want to read it 8-).

It took me 2 years of programming to see that little thing (in Delphi), and later that way to think has helped me alot. Therefore I wanna help other people to understand it, but sorry if your unsatisfied about my help.