Lone Wolf Development Forums  

Go Back   Lone Wolf Development Forums > Hero Lab Forums > HL - Authoring Kit

Notices

Reply
 
Thread Tools Display Modes
rlane187
Junior Member
 
Join Date: Mar 2015
Posts: 28

Old October 14th, 2017, 07:45 PM
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 ||?
rlane187 is offline   #1 Reply With Quote
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,207

Old 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).
Mathias is online now   #2 Reply With Quote
ShadowChemosh
Senior Member
Volunteer Data File Contributor
 
Join Date: Jan 2010
Location: Chicago, IL (USA)
Posts: 10,729

Old October 15th, 2017, 11:15 AM
Quote:
Originally Posted by Mathias View Post
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.

Hero Lab Resources:
Pathfinder - d20pfsrd and Pathfinder Pack Setup
3.5 D&D (d20) - Community Server Setup
5E D&D - Community Server Setup
Hero Lab Help - Hero Lab FAQ, Editor Tutorials and Videos, Editor & Scripting Resources.
Created by the community for the community
- Realm Works kickstarter backer (Alpha Wolf) and Beta tester.
- d20 HL package volunteer editor.
ShadowChemosh is offline   #3 Reply With Quote
rlane187
Junior Member
 
Join Date: Mar 2015
Posts: 28

Old 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?
rlane187 is offline   #4 Reply With Quote
Duggan
Senior Member
Volunteer Data File Contributor
 
Join Date: Nov 2009
Posts: 1,502

Old 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.
Duggan is offline   #5 Reply With Quote
rlane187
Junior Member
 
Join Date: Mar 2015
Posts: 28

Old October 16th, 2017, 10:27 AM
Quote:
Originally Posted by Duggan View Post
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?
rlane187 is offline   #6 Reply With Quote
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,207

Old 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
Mathias is online now   #7 Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:04 AM.


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