firefly2442 Posted June 2, 2014 Posted June 2, 2014 Can I have a conditional "OR" and "AND" in the same trigger statement? For example: if (unit 1 in zone OR unit 2 in zone) AND (FLAG 2 ON) I know it can be done in Lua but in just the editor itself?
ajax Posted June 2, 2014 Posted June 2, 2014 (edited) Yes, but it's kind of a pain. By default, the logical operation is AND between each line. Use the OR button to start a new block of AND conditions. This example is not that bad, but you can imagine it can get messy real quick if you add many more conditions. unit 1 in zone flag2 is on OR unit2 in zone flag2 is on Or in plain language: (Unit1 in zone AND flag2 is on) OR (Unit2 in zone AND flag2 is on) -- which is logically equivalent. Edited June 2, 2014 by ajax
Flagrum Posted June 2, 2014 Posted June 2, 2014 Yes, but it's kind of a pain. By default, the logical operation is AND between each line. Use the OR button to start a new block of AND conditions. This example is not that bad, but you can imagine it can get messy real quick if you add many more conditions. unit 1 in zone flag2 is on OR unit2 in zone flag2 is on Or in plain language: (Unit1 in zone AND flag2 is on) OR (Unit2 in zone AND flag2 is on) -- which is logically equivalent. I think, the OPs question is more targetted at the precedence of the operators. Taken your example, what about Unit1 in zone AND ( flag2 is on OR Unit2 in zone ) AND flag2 is on
baltic_dragon Posted June 2, 2014 Posted June 2, 2014 Can I have a conditional "OR" and "AND" in the same trigger statement? For example: if (unit 1 in zone OR unit 2 in zone) AND (FLAG 2 ON) I know it can be done in Lua but in just the editor itself? I think you just need to use the following: Unit1 in Zone Flag2 ON [or] Unit2 in Zone Flag2 ON Since in your example Flag2 had to be true for both. For more information, please visit my website. If you want to reach me with a bug report, feedback or a question, it is best to do this via my Discord channel. Details about the WinWing draw can be found here. Also, please consider following my channel on Facebook.
sobek Posted June 2, 2014 Posted June 2, 2014 Since in your example Flag2 had to be true for both. That is the same boolean statement, but in his example Flag2 is singled out, which is mathematically considered to be the more simplified state of the whole statement. Good, fast, cheap. Choose any two. Come let's eat grandpa! Use punctuation, save lives!
ajax Posted June 2, 2014 Posted June 2, 2014 (edited) I think, the OPs question is more targetted at the precedence of the operators. Taken your example, what about Unit1 in zone AND ( flag2 is on OR Unit2 in zone ) AND flag2 is on If the statement can be expressed in suitable form, then yes it can be done--which was the OP's question. In your example the equivalent form for the ME would be: Unit1 in zone Flag2 ON OR Unit1 in zone Unit2 in zone Flag2 ON The key is to break it down into a series of binary comparisons using the associative and distributive properties of Boolean math. You can always generate a Truth Table to check for equivalency. Edit: I actually stopped too soon: The simplest equivalent form is: Unit1 in zone Flag2 ON Edited June 2, 2014 by ajax
sobek Posted June 2, 2014 Posted June 2, 2014 (edited) You can always generate a Truth Table to check for equivalency. +1 It is often astounding how much you can condense your boolean statements by just using a truth table. There are some (relatively simple) algorithms for more complex statements, but that would probably be out of scope for this thread. Edit: Unit1 in zone Flag2 ON OR Unit1 in zone Unit2 in zone Flag2 ON Didn't you forget OR Unit 2 in zone FLAG 2 ON? Edit2: Ah i misread your post, i thought you were going off of the original statement instead of Flagrums. Edited June 2, 2014 by sobek Good, fast, cheap. Choose any two. Come let's eat grandpa! Use punctuation, save lives!
ajax Posted June 2, 2014 Posted June 2, 2014 No, I actually didn't. It turns out Unit2 in zone is irrelevant to the "truthness" or "falseness" of the statement as a whole.
sobek Posted June 2, 2014 Posted June 2, 2014 No, I actually didn't. It turns out Unit2 in zone is irrelevant to the "truthness" or "falseness" of the statement as a whole. Yes, sorry about that, see my edit. However i feel that it should be noted that Flagrums example and that of the OP are not equivalent. Good, fast, cheap. Choose any two. Come let's eat grandpa! Use punctuation, save lives!
ajax Posted June 2, 2014 Posted June 2, 2014 Yes, I saw your edit after I already posted.:) It definitely is important to realize that the two examples are different
Home Fries Posted June 2, 2014 Posted June 2, 2014 (edited) You could also break the statement up into two triggers like so: If unit 1 in zone OR unit 2 in zoneThen FLAG(1) = 1then the next statement could be If FLAG(1) TRUE FLAG(2) TRUEthen execute your trigger This is a bit unwieldy for two steps, but if you needed a matrix (similar to Sobek's truth table example) you could create a trigger with flag for each row or column (i.e. each condition) and then triggers based on flags in each of the cells in the matrix (i.e. each action). EDIT: if the triggers with flags have "expiration" (i.e. in your example, if both units leave the area) you will need to add another trigger: If unit 1 not in zone unit 2 not in zone Then FLAG(1) = 0 Edited June 2, 2014 by Home Fries -Home Fries My DCS Files and Skins My DCS TARGET Profile for Cougar or Warthog and MFDs F-14B LANTIRN Guide
firefly2442 Posted June 3, 2014 Author Posted June 3, 2014 Thanks for the replies all. Definitely had some flashbacks to classes long ago regarding truth tables. ;)
Recommended Posts