# The Define Tag

The DEFINE tag is used to create new variables and set their initial values. In addition to the entry for the tag itself this page will go into the details of using variables, formulas and math operators.

Tag Name: DEFINE:x|y

Variables Used (x): Text (Name of variable)

Variables Used (y): Number or Formula (Can be a formula involving pre-defined variables, numbers, operators and user-defined-variables.)

What it does:

- Creates a new variable with the name specified and sets its initial value to the number or formula given.
- 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.

Example:

`DEFINE:MonkeyChop|2`

Creates a new variable named MonkeyChop and sets the initial value to 2.

`DEFINE:MonkeySwing|TL/2`

Creates a new variable named MonkeySwing and sets the initial value to half the characters total level.

## Variables

For those unfamiliar with computer programming or higher math a variable is a symbol which represents a quantity that is not fixed. Most peoples first introduction to variables is in algebra where you might be given a problem such as x+y=z. This is a formula, the x,y and z are variables. PCGen uses variables and formulas for a wide variety of purposes through out the program, some are created in LST files while others are pre-defined, that is they are hard coded and can be used in any formula in any LST file in any game mode. Pre-defined variables are listed below.

Variable Names:

- You can create variable names any way you like - but we recommend using no spaces and a name that is both descriptive and unlikely to conflict with a variable name used in another source for a different purpose. Capitalizing the first letter of each word used in the variable name makes it more readable and more easily identified as a variable. Using all caps to name a variable should be reserved for pre-defined variables that are hard-coded.
- Sometimes the same variable name will be used in different sources if they work together (this happens when one class is based on a class from a different source).
- Certain variables are pre-defined, be careful not to use any of those names when creating your variables.

Pre-defined Variables:

`ACCHECK`

This is the total AC Check penalty from armor and shield.

`ARMORACCHECK`

This is the total AC Check penalty from armor.

`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.

`BASESPELLSTAT`

This is the mod for the class's base spell stat.

`BL=name`

This will return the Bonus Spellcaster Levels to the class specified, which usually come from Prestige classes. For example, lets say you have 2 levels Mystic Theurge which add to both your Cleric and Wizard levels, 3 levels of Archmage which add to your Wizard level, and 1 level of Loremaster which adds to your Cleric level. BL=Wizard would return 5 and BL=Cleric would return 3.

`CHA`

This is the character's CHA modifier.

`CHASCORE`

This is the character's actual Charisma score.

`CON`

This is the character's CON modifier.

`CONSCORE`

This is the character's actual Constitution score.

`COUNT[CLASSES]`

This is the character's number of classes.

`COUNT[DOMAINS]`

This is the character's number of domains.

`COUNT[FEATNAME=name]`

This is the number of feats of the given name. Great for multiple feats that grant bonuses based on the number of times taken.

`COUNT[FEATS]`

This is the character's number of optionally chosen feats (not automatic or virtual).

`COUNT[FEATSALL]`

This is the character's total number of feats (includes automatic and virtual).

`COUNT[FEATTYPE=type]`

This is the character's number of feats matching specified type.

`COUNT[FOLLOWERS]`

This is the character's number of Followers.

`COUNT[LANGUAGES]`

This is the character's number of languages.

`COUNT[SA]`

This is the character's number of unique special abilities.

`COUNT[SKILLS]`

This is the character's number of skills.

`COUNT[SPELLCLASSES]`

This is the character's number of spellcasting classes.

`COUNT[STATS]`

This is the number of defined stats.

`CL`

Class Level of this class.

`CL=name`

Class Level of the named class.

`CLASS=name`

Returns a 1 if the character has the named class, otherwise 0.

`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.

`DEX`

This is the character's DEX modifier.

`DEXSCORE`

This is the character's actual Dexterity score.

`ENCUMBERANCE`

This is a value representing the character's current encumbrance level (0=Light, 1=Medium 2=Heavy, 3=Over-Loaded).

`GRAPPLESIZEMOD`

This is the character's Grappling Size Mod.

`HASDEITY:`

This returns 1 if the character has the named deity, otherwise 0.

`HASFEAT:`

This returns 1 if the character has the named feat, otherwise 0.

`HD`

This is the character's HD (Starting HD or Monster HD. Not HD from classes).

`HIDESIZEMOD`

This is the character's Hide Size Mod.

`INT`

This is the character's INT modifier.

`INTSCORE`

This is the character's actual Intelligence score.

`MOVEBASE`

This is the character's racial-based movement.

`SHIELDACCHECK`

This is the total AC Check penalty from shields.

`SIZE`

This is a value representing the character's current size.

`SIZEMOD`

This is the modifier for the character's current size.

`SKILLRANK=name`

This is the character's Ranks in the named skill replacing { with ( and } with ). e.g. SKILLRANK=Craft {Woodworking} would return the ranks of Craft (Woodworking) since ( and ) have other meanings in DEFINE variables. If used within a JEP formula you will need to enclose it in a variable function e.g. var("SKILLRANK=Craft {Woodworking}")

`SPELLLEVEL`

This is a global variable that is set by the spell's level.

`STR`

This is the character's STR modifier.

`STRSCORE`

This is the character's actual Strength score.

`TL`

Total Level of character.

`VARDEFINED:`

This returns 1 if the character has the named variable, otherwise 0.

`WEIGHT.CARRIED`

is the weight of all carried equipment.

`WEIGHT.EQUIPPED`

is the weight of all equipped items.

`WEIGHT.PC`

is the weight of the PC.

`WEIGHT.TOTAL`

is the weight of all carried items and PC.

`WIS`

This is the character's WIS modifier.

`WISSCORE`

This is the character's actual Wisdom score.

## 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 var() 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 var("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:

`var("CL=Fighter"), var("COUNT[FEATS]"), var("COUNT[FEATTYPE=type]").`

Operators

`2+1`

Addition (+).

`CL-1`

Subtraction (-) - would minus 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.

Updated 5.7.3
Minimums and maximums

The min and max functions support 2 or more arguments, so you can compare 2, 3, 4 or more numbers or variables.

`min(a,b,c)`

Returns the lowest of 'a', 'b' or 'c'.

`max(a,b,c)`

Returns the highest of 'a', 'b' or 'c'.

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 than or Equal (<=). Asks if Class Level is less than or equal to 1.

`(CL>5)&&(TL>5)`

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

`(CL>5)||(TL>5)`

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

Boolean If operator

`if(x,y,z)`

The boolean if operator will return one of two results after evaluating a boolean. The variable x is a boolean result, 0 is false and anything not 0 is true. The variable y is the result returned if x is true, z is the result returned if x is false. Put another way, if x is true (not 0) then the result is y, if x is false (0) then the result is z.

Examples:

`if(CL<10,1,2)`

Asks if Class Level is less than 10 then returns 1 or else returns 2.

`if(CL>=4,10,0)`

Asks if Class Level is greater than or equal to 4 then returns 10 or else returns 0.

`if((CL>5)||(TL>5),2,-4)`

Asks if Class Level or Total Level is greater than 5 then returns 2 or else returns -4.

`if(STR,5,0)`

Asks if Strength modifier is greater than or less than 0 then returns 5 or else returns 0.

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).