• 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

Conditional && and ||

rlane187

Active member
I found the post that spelled out how to perform logical comparisons, but I cannot find how to perform AND and OR statements to combine booleans in an IF statement. Can anyone provide an example or a link to a good tutorial with an example of && and ||?
 
What do && and || mean? You'll never see a doubled character as a operator in HL's scripting language. Do you just mean & and |, and you're pulling in terms from another language?

Also, do you want to use booleans with a script, or are you using booleans in a tag expression? The answer is different in each case

If your question is about tag expressions, here's that section of the wiki: http://hlkitwiki.wolflair.com/index.php5?title=Leveraging_Tags_Via_Tag_Expressions

For scripts, you'll have to be clever with addition and subtraction and multiplication, because the standard if () then can't take booleans.

But,

if (A + B <> 0) then

ends up meaning A or B, as long as both A and B are things that are false at 0 and true if <> 0, and

if (A + B = 2) then

ends up meaning A & B, as long as both A and B are things that are false at 0 and true at 1 (but in this case, it doesn't work if they can be values > 1).
 
What do && and || mean? You'll never see a doubled character as a operator in HL's scripting language. Do you just mean & and |, and you're pulling in terms from another language?
Basically yes. && = "and" and || = "or" in other languages outside of HL (PHP is one off the top of my head). Usually when & is used as contraction function for strings the language uses && to represent a logical IF "and".

FYI ISO standards for SQL uses || to concatenate strings together. The fun of working in many different languages. :D
 
Suppose I have a numeric variable "delta" and I want to test to see if it is within a given range:
Code:
if (delta > 3 AND delta <=6) then
    do stuff
    endif
What should I be using in HL instead of AND?

Suppose I want to know if delta is one of two values:
Code:
if (delta = 3 OR delta = 6) then
    do stuff
    endif
What should I be using in HL instead of OR?
 
For AND
Code:
if (delta > 3) then
  if (delta <=6) then
    ~ do stuff
    endif
  endif

For OR (can result in duplication if doing "do stuff" twice has different effects than running it once)
Code:
if (delta = 3) then
  ~ do stuff
  endif

if (delta =6) then
  ~ do stuff
  endif

Alternately, if you can turn it into a tag check (including a tag value check), things get more flexible.
 
For AND
Code:
if (delta > 3) then
  if (delta <=6) then
    ~ do stuff
    endif
  endif

For OR (can result in duplication if doing "do stuff" twice has different effects than running it once)
Code:
if (delta = 3) then
  ~ do stuff
  endif

if (delta =6) then
  ~ do stuff
  endif

Alternately, if you can turn it into a tag check (including a tag value check), things get more flexible.

I would love to use tags for it, but it is calculating how many creation points the user is burning on attributes during creation.

To summarize the takeaway from this, I need to nest any if statements for logical AND or OR?
 
Depending on how things are stored, tagexpr may work:

Code:
if (tagexpr[(fieldval:trtUser >= 3) & (fieldval:trtUser <= 6)] <> 0) then
 
Back
Top