Lone Wolf Development Forums

Lone Wolf Development Forums (http://forums.wolflair.com/index.php)
-   HL - Authoring Kit (http://forums.wolflair.com/forumdisplay.php?f=58)
-   -   Conditional && and || (http://forums.wolflair.com/showthread.php?t=59329)

rlane187 October 14th, 2017 07:45 PM

Conditional && and ||
 
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 ||?

Mathias October 15th, 2017 09:27 AM

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....ag_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).

ShadowChemosh October 15th, 2017 11:15 AM

Quote:

Originally Posted by Mathias (Post 257425)
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

rlane187 October 16th, 2017 03:25 AM

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?

Duggan October 16th, 2017 06:21 AM

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.

rlane187 October 16th, 2017 10:27 AM

Quote:

Originally Posted by Duggan (Post 257450)
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?

Mathias October 16th, 2017 11:01 AM

Depending on how things are stored, tagexpr may work:

Code:

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


All times are GMT -8. The time now is 12:10 PM.

Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.