FUNCTION & VALUE 6.08

From PCGen Wiki
Revision as of 00:10, 7 January 2018 by LegacyKing (talk | contribs) (Created page with "==FUNCTION & VALUE== ====RAW==== ${pc.val.x} (again, where the "x" is the new variable now holding new FACE). 2 new tokens for the Data Control file: FUNCTION:x...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

FUNCTION & VALUE

RAW

  ${pc.val.x}

(again, where the "x" is the new variable now holding new FACE).


2 new tokens for the Data Control file:

  FUNCTION:x
  VALUE:x


  FUNCTION:x

Must appear as the first item on the line in a data control file Takes one argument, a function name Must be a "legal" function name, meaning: - starts with a letter, e.g. A-Z, additional legal characters are 0-9 and _ (none of those as the first character) - No spaces, no other special characters. - Are case insensitive (as many other things in LST files)

This defines the function name as it will be used in a formula in the LST data files. If a FUNCTION appears more than once, the other characteristics (currently VALUE) must be identical.

  VALUE:x

Must appear as an additional token on the line of a FUNCTION: in the data control file

The provided value must be a value formula. This means it must have valid variable names, valid function names, matching parenthesis, etc. etc. In addition to all of the build-in functions (e.g. if, ceil, round), two additional items can be used:

(1) the arg(n) function. The arg function is a "local" function to the VALUE: part of a FUNCTION (it can not generally be used in LST files). The arg function takes one argument. It MUST be a Integer >= 0.

(2) Any previously defined FUNCTION. This MUST appear in the file before the current Function or in a file processed before the current file.

Meaning:

  FUNCTION:d20mod <> VALUE:floor((arg(0)-10)/2)
  FUNCTION:embed <> VALUE:d20mod(arg(0)*4

is legal, while:

  FUNCTION:embed <> VALUE:d20mod(arg(0)*4
  FUNCTION:d20mod <> VALUE:floor((arg(0)-10)/2)

...is not legal (since d20mod does not yet exist when embed is encountered)

When a function is used in LST data, it is called by the name provided in the FUNCTION token. It requires a certain number of arguments. This exactly matches the integer one greater than the highest number of the arg(n) function provided in the VALUE part of a FUNCTION (In computer science terms, the arg(n) function is zero-indexed) The provided arguments can be any legal formula, so:

  d20Mod(INT)
  d20Mod(INT+4)

are both perfectly legal.

For example:

  FUNCTION:d20Mod <> VALUE:floor((arg(0)-10)/2)

Note the arg(n) function here uses ZERO, not ONE.

This would then be used in LST data as:

  d20Mod(n)

It will catch both d20Mod() and d20Mod(14,5) as errors (too few or too many args). It would also catch: d20Mod("mystring") as an error (wrong format - requires a Number, found a String). The n is substituted where "arg(0)" appears in the "VALUE"... so a statmod would be as easy as:

  d20Mod(INT)

or some such... Direct values can also be used, e.g. d20Mod(10) would return 0.


Some other notes:

Note that the function actually has to be *used* (not just defined) for the errors to be caught (since it can't guess at overall context)

An embedding example can be found here: https://groups.yahoo.com/neo/groups/pcgen_experimental/conversations/messages/19549