Loading ...
Sorry, an error occurred while loading the content.

[DOCS] JEP update to DEFINE page

Expand Messages
  • Eddy Anthony
    This is an update to information on the DEFINE page (List files/Global). All you programmer please double check me, I m concerned about my entry for the use of
    Message 1 of 3 , Jul 1, 2004
    • 0 Attachment
      This is an update to information on the DEFINE page (List files/Global). All
      you programmer please double check me, I'm concerned about my entry for the
      use of Boolean And & Or specifically. This is by no means comprehensive but
      I believe it covers what us data monkeys need to know :-D
      There is a link on the page back to the JEP documentation:
      http://www.singularsys.com/jep/

      As always any comment are welcome.
      --
      ~ Eddy
      ~ Doc Chimp, Data Tamarin
      ~ PCGen BoD Documentation Second
      __________________________________________________________
      Formulas and Math Operators

      Important: Starting with version 5.7.1 PCGen has incorporated the JEP (Java
      Mathematical Expression Parser) library. This was done because the original
      code which has evolved over time is problematic due to its complexity and
      lack of documentation. The JEP library has a clearly defined grammar which
      is available on the web site. JEP supports user defined variables,
      constants, and functions. A number of common mathematical functions and
      constants are included. As a fall back, if the JEP parser fails to parse the
      function then the old code is called. At some point in the future the old
      code support will be dropped and all formulas must be in JEP syntax.

      Using variables within JEP expressions

      In most cases variables can be used directly in an expression, however there
      are some cases when you must use the getvar() function. This is because some
      variables can contain characters which are not valid JEP variables. For
      example the variable CL can be used in a formula without a problem but the
      variable CL=Fighter cannot be used because of the "=" symbol. In these cases
      you must use getvar("CL=Fighter") in the formula for it to parse correctly.
      The formal description of a JEP variable is "a letter followed by one or
      more letters and digits" where a letter is defined as: '$', '_', a-z and
      A-Z.

      Examples of variables that may be used alone:
      CL, TL, ARMORACCHECK, BardicKnowledgeLevel, TirelessRage.

      Examples of variables that must be called with the getvar() function:
      getvar("CL=Fighter"),
      getvar("COUNT[FEATS]"),
      getvar("COUNT[FEATTYPE=type]").

      Operators

      2+1
      Addition (+).

      CL-1
      Subtraction (-) - would subtract one from the Class Level.

      CL/2
      Division (/) - would divide the Class Level by two.

      CL*3
      Multiplication (*) - would multiply the Class Level by three.

      ((CL+1)+(3*TL)/2)/4
      Parenthesis () nesting - the result of three multiplied by Total Level
      divided by two, plus Class Level + 1 is divided by four.

      Minimums and maximums

      min(a,b)
      Returns the lowest of 'a' and 'b'.

      max(a,b)
      Returns the highest of 'a' and 'b'.

      Truncation, rounding up and down.

      floor(a)
      Returns the highest integer that is less than 'a'.

      ceil(a)
      Returns the lowest integer that is greater than 'a'.

      Boolean operators
      Boolean operators are also fully supported. Boolean expressions are
      evaluated to be either 1 or 0 (true or false respectively).

      CL==1
      Equal (==). Asks if Class Level is equal to 1.

      CL!=1
      Not Equal (!=). Asks if Class Level is not equal to 1.

      CL>1
      Greater than (>). Asks if Class Level is greater than 1.

      CL<1
      Less than (<). Asks if Class Level is less than 1.

      CL>=1
      Greater than or Equal (>=). Asks if Class Level is greater than or equal to
      1.

      CL<=1
      Less thanor Equal (<=). Asks if Class Level is less than or equal to 1.

      CL&&TL>5
      Boolean And (&&). Asks if Class Level and Total Level are greater than 5.

      CL||TL>5
      Boolean Or (||). Asks if Class Level or Total Level is greater than 5.

      Deprecated operators

      The following operators are deprecated as of version 5.7.1. The syntax will
      be replaced with JEP syntax.

      ((TL/3).TRUNC)*2
      Truncation - would divide TL by 3, truncate (or round down) and then
      multiply by 2.
      Deprecated, use floor(a).

      2MIN4
      Minimum - would return 2 since it's taking the minimum of the two values
      (MIN is always between the values).
      Deprecated, use min(a,b).

      2MAX4
      Maximum - would return 4 since it's the max of the two values (MAX is always
      between the values).
      Deprecated, use max(a,b).

      Operator order of processing:

      Anything within ()'s are done first, and processing is done left-to-right.

      2+(3*5+2)/2

      Would become 2+(15+2)/2 (3*5 replaced)
      then 2+17/2 (15+2 replaced)
      then 19/2 (2+17 replaced)
      then 9.5 (result of 19/2).
    • Michael Tucker
      ... Happy to oblige. It looks good to me, except for the booleans. You ... I believe this is the same as: (CL) && (TL 5) In other words, it would want to
      Message 2 of 3 , Jul 1, 2004
      • 0 Attachment
        On Jul 1, 2004, at 7:18 PM, Eddy Anthony wrote:

        > This is an update to information on the DEFINE page (List
        > files/Global). All
        > you programmer please double check me, I'm concerned about my entry
        > for the
        > use of Boolean And & Or specifically. This is by no means
        > comprehensive but
        > I believe it covers what us data monkeys need to know :-D
        > There is a link on the page back to the JEP documentation:
        > http://www.singularsys.com/jep/
        >
        > As always any comment are welcome.
        > --
        > ~ Eddy
        > ~ Doc Chimp, Data Tamarin
        > ~ PCGen BoD Documentation Second
        >

        Happy to oblige. It looks good to me, except for the booleans. You
        wrote:

        > CL&&TL>5
        > Boolean And (&&). Asks if Class Level and Total Level are greater than
        > 5.
        >

        I believe this is the same as:
        (CL) && (TL>5)

        In other words, it would want to evaluate (CL) as a boolean (probably
        "false" if zero, "true" if not zero), get the boolean result of (TL>5),
        and AND the two boolean values. I.e., "true if CL is not zero AND TL is
        greater than 5".

        If you want to express "true if both CL and TL are greater than 5", I
        believe it should be like this:
        (CL>5)&&(TL>5)

        > CL||TL>5
        > Boolean Or (||). Asks if Class Level or Total Level is greater than 5.
        >

        Pretty much the same comments as above. I believe that your example
        really evaluates to:
        (CL)||(TL>5)

        In other words, "true if CL is not zero OR TL is greater than 5". If
        you want "true if either CL or TL is greater than 5", I think you'd
        want:
        (CL>5)||(TL>5)

        But I'm not as "up" with JEP as I'd like to be. One of the other
        monkeys, please correct me if I'm wrong.

        Michael
      • Eddy Anthony
        ... You are correct, I had the feeling I had it wrong. Did some testing in PCGen using the get variable function on the console. (CL) evaluates exactly as you
        Message 3 of 3 , Jul 2, 2004
        • 0 Attachment
          On 7/1/04 11:50 PM, "Michael Tucker" <mtucker@...> wrote:

          > Happy to oblige. It looks good to me, except for the booleans. You
          > wrote:
          >
          >> CL&&TL>5
          >> Boolean And (&&). Asks if Class Level and Total Level are greater than
          >> 5.

          > I believe this is the same as:
          > (CL) && (TL>5)
          >
          > In other words, it would want to evaluate (CL) as a boolean (probably
          > "false" if zero, "true" if not zero), get the boolean result of (TL>5),
          > and AND the two boolean values. I.e., "true if CL is not zero AND TL is
          > greater than 5".
          >
          > If you want to express "true if both CL and TL are greater than 5", I
          > believe it should be like this:
          > (CL>5)&&(TL>5)

          You are correct, I had the feeling I had it wrong. Did some testing in PCGen
          using the get variable function on the console. (CL) evaluates exactly as
          you said it would. Thanks.
          --
          ~ Eddy
          ~ Doc Chimp, Data Tamarin
          ~ PCGen BoD Documentation Second
        Your message has been successfully submitted and would be delivered to recipients shortly.