Various code questions
#6
#5 is a basic TRUTH check. In BASIC, **everything** tends to break down to a simple TRUE or FALSE type evaluation. If a variable, or the result of an action, gives a value of ZERO, we consider that to be FALSE. Anything else is considered TRUE.

Let's take a look at IF x > 3 THEN....

x > 3 is a simple math statement that gives us two results. (Don't believe it? Just try a little PRINT x > 3 and change the value of x a few times.) IF x is less than or equal to 3, it returns a value of ZERO, which is <FALSE>. If x is greater than 3, it returns a value of -1, which is <TRUE>. This true/false value determines whether we process that IF statement or not.

Now, let's take a look at IF X THEN....

X is a simple variable. In this case, we don't have to do anything with it, except look up its value to know our results. If X is 0, then the result is FALSE. Anything else is TRUE.

So, in the case of the following:
m2Dn = _MouseButton(2) ' button 2 processing
If m2Dn Then ' Btn 2 down

m2Dn gets its value based on the state of the right mouse button. (Mouse Button 2) If the button is down, the value is -1. IF the button is up, the value is 0.

IF m2Dn THEN .... If m2Dn is <TRUE>, then we process the code inside the IF condition. Otherwise, we don't. In this case, the only true value we can get is -1, and we only have it when the button is down. The statement basically says, "IF the right mouse button is down THEN..."
Reply


Messages In This Thread
Various code questions - by james2464 - 08-17-2022, 01:57 PM
RE: Various code questions - by mnrvovrfc - 08-17-2022, 02:09 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 02:09 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 02:13 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 02:21 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 02:30 PM
RE: Various code questions - by OldMoses - 08-17-2022, 04:55 PM
RE: Various code questions - by james2464 - 08-17-2022, 06:30 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 06:35 PM
RE: Various code questions - by james2464 - 08-17-2022, 06:43 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 06:53 PM
RE: Various code questions - by Kernelpanic - 08-17-2022, 08:32 PM
RE: Various code questions - by SMcNeill - 08-17-2022, 09:25 PM
RE: Various code questions - by Kernelpanic - 08-18-2022, 01:31 PM



Users browsing this thread: 3 Guest(s)