I'm going to break down the incredibly powerful embedded IF/Then/Else structure as well as show how to nest them. I was familiar with this concept not only from various programming languages but also MQ2Hud code. This particular structure can streamline your SHITs, HUD and even Macro code. This comes up enough I thought I'd break it down into its simplest terms and show the variations that make it so powerful.
The basic structure is:
Rich (BB code):
${If[SomeCondition,True,False]}
To use a real MQ2 test:
Rich (BB code):
${If[${Me.FeetWet},True,False]}
Obviously we want to do something in the TRUE branch:
Rich (BB code):
${If[${Me.FeetWet},/shout ARGH I WET Myself!!!,False]}
And the FALSE branch:
Rich (BB code):
${If[${Me.FeetWet},True,/shout Its OK, I'm wearing a DIAPER!!!]}
Putting them together:
Rich (BB code):
${If[${Me.FeetWet},/shout ARGH I WET Myself!!!,/shout Its OK, I'm wearing a DIAPER!!!]}
The basic structure for NESTING the structure in the TRUE branch of the outer condition:
Rich (BB code):
${If[SomeCondition,${If[SomeCondition,True,False]},False]}
The basic structure for NESTING the structure in the FALSE branch of the outer condition:
Rich (BB code):
${If[SomeCondition,True,${If[SomeCondition,True,False]}]}
Now you might be thinking, but Incog you hairy long bearded sillimon, I can put multiple tests using AND and OR in the original test! Yes, you can. But upon the FALSE branch you don't know which of multiple possible test conditions caused the FALSE to fire. When using nested conditions you have total control of what failed and what passed without having to do additional tests (which is unfortunately pretty common).
The basic structure for NESTING the structure in the FALSE AND the TRUE branch of the outer condition:
Rich (BB code):
${If[SomeCondition,${If[SomeCondition,True,False]},${If[SomeCondition,True,False]}]}
Now it's important to note that you don't have to do something in any of the resultant branches. You could do:
Rich (BB code):
${If[SomeCondition,,]}
So if you want to 'do something' only on the TRUE branch you could do:
Rich (BB code):
${If[SomeCondition,True,]}
Now you might be thinking of how you might use some of these variations (or even why). I would point out that understanding the structure and its intricacies allow you a broader range of options when you DO come up with something you are trying to solve. Lets not let our understanding be the limiting factor in the solutions we are trying to discover.
The first thing that comes to mind is that most if not all shits only do something IF the condition is true (even if its proceeded by the negative ! it is still regarded as "true" from a syntax perspective). So using this structure gives us an alternate firing branch without having to create another shit to test the opposite condition. To reiterate, we usually write shits that test this and do that. With this structure we are afforded a full if/then/else solution.
To use a real-world example; most ppl put some text (say ${Zone}) in their HUD. They might put a test/condition. However I've seen a lot of HUD code that simply adds another test and either overwrites the first text, or given enough white space adds to a given line whereas we could put the whole line in an if/then/else custom tailoring the output under our control rather than having to blndly space out more text in hopes it fits. If that doesn't make sense, ok, you haven't done it. But it is common to blindly put the result of a condition in the HUD and then trying to add to it blindly where we could have utilized the if/then/else structure to avoid that.
Rich (BB code):
Time=3,4,450,85,0,255,0,Time: ${Time} GameTime: ${GameTime.Hour}:${GameTime.Minute} - ${If[${Bool[${GameTime.Night}]},Night,Day]}
Another HUD example:
Rich (BB code):
Macro1=3,4,600,100,0,255,0,${If[${Macro.Name.NotEqual["NULL"]} && ${Macro.Paused},${Macro.Name} PAUSED,${If[${Macro.Name.NotEqual["NULL"]}, ${Macro.Name},]}]}
Now in Holy/Down shits, it is customary to have a test of some kind and then do something. I have seen shits code that then tests for the opposite condition in its own shit. Utilizing the if/then/else conditional structure allows us to do all that in one shit, one line, all at the same time. Here is an example of double duty where the coder is trying to fire Blast of Anger when Phantom Aggressor is not ready, and Phantom Aggressor if it is:
Rich (BB code):
holyshit1=/if (!${Me.CombatAbilityReady[Phantom Aggressor]} && !${Me.ActiveDisc.ID} && ${Target.PctHPs}<100) /alt act 3646
holyshit2=/if (${Me.CombatAbilityReady[Phantom Aggressor]} && !${Me.ActiveDisc.ID} && ${Target.PctHPs}<100) /disc 40012
Here is a better way to code it:
Rich (BB code):
holyshit1=/if (${If[${Me.CombatAbilityReady[Phantom Aggressor]},/disc 40012,/alt act 3646]})
Holys and Downs fire multiple times a second. Now that we have the capacity to code 60 shits, that can create noticable lag. Why incur the load of multiple tests when it can be done in one.
Now since macro code allows us to do else branches, and elseif branches, this particular structure doesn't offer us anything we otherwise didn't have. It can however come in handy if you want a single line to accomplish if/then/else in tidy fashion. I did a quick glance thru some macs to see if I could find an example but nothing came up quickly. So I did a test in the MQ2Window command line:
Rich (BB code):
/echo ${If[${Zone.ID}==151,/say YAY I found the Bazaar!,/say Goddamnit Where the hell is the BAZ man?]}
/echo ${If[${Zone.ID}==152,/say YAY I found the Bazaar!,/say Goddamnit Where the hell is the BAZ man?]}
And it did work so I assumed you could use /docommand ${If[SomeCondition,True,False]} to fire something in a social. I tested that approach in a macro:
Rich (BB code):
sub main
/docommand ${If[${Zone.ID}==151,/say YAY I found the Bazaar!,/say Goddamnit Where the hell is the BAZ man?]}
/return
And that worked as well. When I set the test to 151, it fired the TRUE branch. When I set it to 152 it fired the FALSE branch. I will continue to try and find examples of how some of the heavy-duty macro writers have used this structure in their code. I did a quick scan thru KissAssist but nothing jumped out at me (and there are some 7k+ lines of code, and hundreds of IFs, I coulda missed it).
Last edited:


