The Define Tag

What does DEFINE do?

DEFINE: has 2 parts, a name and a value. DEFINE:name|value where value can be a formula involving pre-defined variables, numbers, operators and user-defined-variables. Many classes use PREVAR tags, which are pre-requisites based upon variable values. These values are calculated by getting the value of the variable with the highest DEFINE value, and then adding any BONUS: tags which apply to it. For example, if a class had PREVARGT:Hopscotch,3 would mean that the character only qualifies for the class if they have a Hopscotch value higher than 3 (GT = Greater Than). PCGen scans the characters race, templates, classes, feats, skills, deity, domains and equipped items for DEFINE: tags that match this variable name. If it finds more than one, it keeps the one with the higher value. PCGen then scans the same list of items and looks for those with BONUS:VAR|Hopscotch tags and after figuring out which ones stack, adds those to the highest define value. The resulting value is then compared to the PREVARGT's requirement, which is 3 in this case, and PCGen then indicates if the character meets this requirement or not.

What pre-defined variables are there?

You can create variable names any way you like - but we recommend using all capital letters with no spaces and use a name that is both descriptive and unlikely to conflict with a variable name used in another source for a different purpose. Sometimes the same variable name will be used in different sources if they work together (this happens when one class is based no a class from a different source). The only caveat to naming your variables is that certain names are already predefined:
pre-defined variable description
BAB For classes which have O (for Other) as their BAB progression, you can use a formula for their BAB progression. e.g. DEFINE:BAB|2*CL would be +2 per class-level
CL Class Level of this class
CL=name Class Level of the named class
CLASSLEVEL=name Class Level of the named class, replacing { with ( and } with ). e.g. CLASSLEVEL=Warrior {Ruby} would return the level of Warrior (Ruby) since ( and ) have other meanings in DEFINE variables.
TL Total Level of character
CLASS=name Returns a 1 if the character has the named class, otherwise 0.
FORTBASE similar to BAB, classes can define non-standard check progressions.
REFLEXBASE similar to BAB, classes can define non-standard check progressions.
WILLBASE similar to BAB, classes can define non-standard check progressions.
STR This is the character's STR modifier
STRSCORE This is the character's actual Strength score.
DEX This is the character's DEX modifier
DEXSCORE This is the character's actual Dexterity score.
CON This is the character's CON modifier
CONSCORE This is the character's actual Constitution score.
INT This is the character's INT modifier
INTSCORE This is the character's actual Intelligence score.
WIS This is the character's WIS modifier
WISSCORE This is the character's actual Wisdom score.
CHA This is the character's CHA modifier
CHASCORE This is the character's actual Charisma score.
HD This is the character's HD
SHIELDACHECK This is the character's current shield Armor Check value
SIZE This is a value representing the character's current size
SIZEMODThis is the modifier for the character's current size
ENCUMBERANCE This is a value representing the character's current encumberance level (0=Light, 1=Medium 2=Heavy, 3=Over-Loaded)
GRAPPLESIZEMOD This is the character's Grappling Size Mod
HIDESIZEMOD This is the character's Hide Size Mod
MOVEBASE This is the character's racial-based movement.
GRAPPLESIZEMOD This is the character's Grappling Size Mod
COUNT[FOLLOWERS] This is the character's number of Followers
COUNT[STATS] This is the number of defined stats
COUNT[SKILLS] This is the character's number of skills
COUNT[FEATS] This is the character's number of optionally chosen feats (not automatic or virtual)
COUNT[FEATSALL] This is the character's total numher of feats (includes automatic and virtual)
COUNT[FEATTYPE=type] This is the character's number of feats matching specified type
COUNT[SPELLCLASSES] This is the character's number of spellcasting classes
COUNT[CLASSES] This is the character's number of classes
COUNT[DOMAINS] This is the character's number of domains
COUNT[SA] This is the character's number of unique special abilities
COUNT[LANGUAGES] This is the character's number of languages
VARDEFINED: returns 1 if the character has the named variable in a DEFINE: tag, otherwise 0.
HASFEAT: returns 1 if the character has the named feat, otherwise 0.
HASDEITY: returns 1 if the character has the named deith, otherwise 0.

What kinds of operators are allowed?

plus (+) e.g. 2+1
minus (-) e.g. 2-1
division (/) e.g. CL/2
multiplication (*) e.g. CL*3
nesting ()'s e.g. ((CL+1)+(2*TL)/2)/4
.TRUNC e.g. (TL/3.TRUNC)*2 would divide TL by 3, truncate and then multiply by 2.
MIN e.g. 2MIN4 would return 2 since it's taking the minimum of the two valuse (MIN is always between the values).
MAX e.g. 2MAX4 would return 4 since it's the max of the two values.

In what order are formulas processed?

Anything within ()'s are done first, and processing is done left-to-right. e.g. 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).