• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Boolean Logic within Conditionals...

GodPole

Well-known member
I'm in the process of writing a pretty extensive script that requires the use of Boolean "ands" (&) inside conditional statements:

If (a=1) & (b=2) then...

...and so forth.

I found in a rather old post that this was on the roadmap, but not a high priority.

Is this still the case?

Use of an "&" inside a conditional is throwing errors in the latest version of HL.


I would rather not have to write a bunch of nested if-then statements if I don't need to.

Any help on this is greatly appreciated.

Thanks.

-GP
 
For the moment, there are no boolean operators inside of conditional statements. It is a shame, because I too have needed them and resorted to nested conditionals to get the job done.
 
You can do Boolean with OR, AND, but not AND & OR. A good number of HL scripts do this already.

For OR logic you simply add the variables together and if the total is 1 or higher then DO.

If you wanted Boolean AND logic where all the testes are TRUE then again you can do this. Add the results together and test against the total number of tests. So three Boolean AND logic would test against 3.

But yea if you want to do Boolean AND & OR logic in the same IF statement you can't currently. At least I have not seen how.
 
There is no current support for traditional boolean logic within conditionals. However, the vast array of boolean tests within conditionals comprise testing two or more tag behaviors. Tests of tags can be readily combined in a variety of ways using pseudo-boolean and proper boolean operations. For example....

If you want to see if a pick has both TagA and TagB, you can use the notation below:
Code:
if (pick.tagis[group.TagA] + pick.tagis[group.TagB] >= 2) then

If you want to see if a pick has either TagA or TagB:
Code:
if (pick.tagis[group.TagA] + pick.tagis[group.TagB] > 0) then

If you want to check for one tag but not the other:
Code:
if (pick.tagis[group.TagA] + !pick.tagis[group.TagB] >= 2) then

For an XOR combination:
Code:
if (pick.tagis[group.TagA] + pick.tagis[group.TagB] = 1) then

You can also build a complex tag expression with boolean logic and test for that:
Code:
if (pick.tagexpr[group.TagA & !group.TagB] > 0) then

You can even check tags using wildcards:
Code:
if (hero.tagexpr[!Hero.Creature & Hero.Faction?]) then

Just about everything within Hero Lab is built around and upon tags. The reason for that is simple: tags provide a great deal of flexibility and are extremely efficient internally. It's quite easy to leverage tags in a wide array of boolean operations without the need for more traditional boolean operators. So we haven't added that to the language yet.

Please give the above examples a try and see if they might work for your needs. There are also a lot of other ways that tags can be leverage that follow in the same vein as the examples I gave. If you have a question about how to accomplish a particular objective that seems like it should leverage boolean logic, post it and some of us can help out with how best to structure it. I'm sure there are some cases where nested "if" statements will be required, but they shouldn't be needed all that often if you're leveraging tags.

Hope this helps....
 
You can also build a complex tag expression with boolean logic and test for that:
Code:
if (pick.tagexpr[group.TagA & !group.TagB] > 0) then

You can even check tags using wildcards:
Code:
if (hero.tagexpr[!Hero.Creature & Hero.Faction?]) then

Hope this helps....
Oh nice didn't know about these. Thanks Rob.
 
Back
Top