LookUp

From PCGen Wiki
Jump to: navigation, search

Example of Lookup Table

  STARTTABLE:Carrying Capacity,
  Strength,Capacity
  NUMBER,NUMBER
  1,10
  2,20
  ...
  29,1400
  ENDTABLE:Carrying Capacity,

Syntax

  STARTTABLE:<tableName>
  <rowName,ColumnName>
  <VarType,VarType>
  <rowNameValue,ColumnNameValue>
  ...
  ENDTABLE:<tableName>


Ignoring some of the diagnosis of bad inputs that will be necessary, this is the key logic:

  (1) This format of START and END allows more than one table per file (avoids sprawl)
  (2) Trailing commas are ignored (this allows the STARTTABLE and ENDTABLE lines to have blank cells where the rest are the table contents... we don't want to complain on minor things that may tools will do.)
  (3) Blank lines will be ignored.  This includes lines with commas but without content. (allows tables to be separated by blank lines or lines of all commas)
  (4) The column names (Strength,Capacity) are always the first line of the table.  The Formats are always the second line.  The rest of the lines are content of the table
  (5) Attempts to use embedded line breaks or embedded quotes may or may not be supported by the parsing system, but certainly aren't supported for purposes of PCGen.
  Optionally:
  (6) Lines that have the first cell starting with "#" are considered comment lines and will be ignored.  This will likely need to include if the first cell is escaped in quotes, just for protection from any tools that quote by default.

The dicestep then becomes more like:

  STARTTABLE:Dice Step,,,,,,,,,
  Dice,DOWN5,DOWN4,DOWN3,DOWN2,DOWN1,SELF,UP1,UP2,UP3,UP4,UP5,...
  DICE,DICE,DICE,DICE,DICE,DICE,DICE,DICE,DICE,DICE,DICE,DICE,...
  ...
  1d3,-,-,0,1,1d2,1d3,1d4,1d6,1d8,2d6,3d6,...
  ...
  ENDTABLE:Dice Step,,,,,,,,,


Example of Using LookUp

lookup(X,Y,Z)

  X is a table name.  This must resolve in the formula system to a String that is a valid table name.
  Y is the lookup value in the table.  It must match the format of the column in the table.
  Z is the target column name.  This must resolve in the formula system to a String that is a valid table column name in the table named X

Thus max load calculation would be something like:

  lookup("Carrying Capacity",roundDown(StrScore),"Capacity")*SizeMult

In a formula - data controlled in a MODIFY.

(This ignores the over 29 logic, as well as how SizeMult was initialized (presumably from the SIZE: object), but those are not difficult.)

To make the Dice Step example work, we would need something to find the correct column from the offset:

  STARTTABLE:Step Column,
  Steps,Name
  NUMBER,STRING
  -5,DOWN5
  -4,DOWN4
  ...
  0,SELF
  1,UP1
  ...
  ENDTABLE:Step Column,

The query would then look up the correct column name and use that column from Dice Step:

  lookup("Dice Step",BaseDamage,lookup("Step Column",CurrentSize-BaseSize,"Name"))

Notes and extras

One neat item would be that we could alter the query above to extract the table name into the Global Modifier file:

  MODIFY:DiceStepTable|SET|"Dice Step"
  lookup(DiceStepTable,BaseDamage,lookup("Step Column",CurrentSize-BaseSize,"Name"))


Now, if someone needs different dice steps for some reason... they can override the DiceStepTable variable and it will look up in a different table... so expansions could truly be expansions and not have to reach back into core PCC files in order to change key behaviors.


Another neat item is identical cast/known tables could be shared - the numbers would only need to be typed in once... :) ... since they are external to the Class file at that point... or if a subclass alters the default, just create a new table rather than having to BONUS/MODIFY all the numbers with adding and subtracting...