Playing with the mouse
#2
I avoid Boolean logic like the plague. Steve seems to like it, so I'll let him explain better if he reads this post.

I do like the use in this example; otherwise the difference is...

When you are using AND in the first condition, you only need to use ACTIVE once, because it combines with the 4 mouse pointer locations. In the second condition, you use OR to indicate the pointer has been moved outside the square, and since OR separates, you now need to place ACTIVE with each OR statement to achieve the same results...

Code: (Select All)
ELSEIF Active AND Mouse.StartX < 500 OR Active AND Mouse.StartX > 600 OR Active AND Mouse.StartY < 200 OR Active AND Mouse.StartY > 300 THEN

So using EQV as you did with...

Code: (Select All)
ELSEIF Active EQV Mouse.StartX < 500 OR Mouse.StartX > 600 OR Mouse.StartY < 200 OR Mouse.StartY > 300 THEN

...brilliantly reduces the repetition of ACTIVE in the prior use. +2 for that!

So when ACTIVE is FALSE we want to not re-enter that second condition again until ACTIVE becomes TRUE. The OR statements without EQV screw that up, because any one of the mouse location OR statements being true, that don't have an ACTIVE variable combined with it, makes the program flow return there again and again. Now with EQV, we use ACTIVE just once and compare it to EACH of the the 4 mouse position OR statements, so when just one of them is FALSE the whole condition is FALSE.

The basic why I would illustrate this is with the following group of OR statements with only the last of the 4 OR comparisons being true.

Code: (Select All)
PRINT 1 > 2 OR 3 > 4 OR 5 > 6 OR 10 > 0
Active = -1 ' True.
PRINT Active EQV 1 > 2 OR 3 > 4 OR 5 > 6 OR 10 > 0
Active = 0 ' True.
PRINT Active EQV 1 > 2 OR 3 > 4 OR 5 > 6 OR 10 > 0

Notice how EQV nicely made the comparison if one of the OR statements is true, but ACTIVE is false, the condition is now FALSE.

Just for fun, I also included the Boolean table from the wiki:

Code: (Select All)
  ┌───────────────┬────────────────────────────────────────────────────────┐
  │   Operands    │                   Logical operations                   │
  ├───────┬───────┼───────┬─────────┬────────┬─────────┬─────────┬─────────┤
  │   A   │   B   │ NOT B │ A AND B │ A OR B │ A XOR B │ A EQV B │ A IMP B │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ true  │ true  │ false │  true   │ true   │  false  │  true   │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ true  │ false │ true  │  false  │ true   │  true   │  false  │  false  │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ false │ true  │ false │  false  │ true   │  true   │  false  │  true   │
  ├───────┼───────┼───────┼─────────┼────────┼─────────┼─────────┼─────────┤
  │ false │ false │ true  │  false  │ false  │  false  │  true   │  true   │
  └───────┴───────┴───────┴─────────┴────────┴─────────┴─────────┴─────────┘   

Pete
Reply


Messages In This Thread
Playing with the mouse - by NasaCow - 12-11-2022, 07:59 AM
RE: Playing with the mouse - by Pete - 12-11-2022, 02:47 PM
RE: Playing with the mouse - by NasaCow - 12-11-2022, 03:03 PM
RE: Playing with the mouse - by SMcNeill - 12-11-2022, 02:51 PM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 03:10 PM
RE: Playing with the mouse - by Pete - 12-11-2022, 04:50 PM
RE: Playing with the mouse - by mnrvovrfc - 12-11-2022, 06:36 PM
RE: Playing with the mouse - by Pete - 12-11-2022, 06:39 PM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 05:39 PM
RE: Playing with the mouse - by SMcNeill - 12-11-2022, 08:21 PM
RE: Playing with the mouse - by NasaCow - 12-12-2022, 09:38 AM
RE: Playing with the mouse - by TempodiBasic - 12-11-2022, 06:24 PM
RE: Playing with the mouse - by Pete - 12-12-2022, 12:22 AM
RE: Playing with the mouse - by TempodiBasic - 12-13-2022, 02:45 PM



Users browsing this thread: 2 Guest(s)