NOT

Blitz3D Forums/Blitz3D Programming/NOT

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.