Skip to content

Expressions ​

Use expressions to calculate numeric, text, and boolean values in configuration, so costs, chances, scaling, requirements, rewards, and random values never need to be hard-coded

Variables ​

First, keep this in mind: variables are supplied entirely by the calling module and the current field, and CoreLib does not inject one global set of business variables into every formula. Cost, success-rate, attribute-value, action, and message fields may use different contexts even within the same plugin

To find out which variables a field accepts, see the Variable, Expression, and Placeholder Context Matrix, which lists the real variables, units, and scope restrictions derived from the production parsers, services, models, and PlaceholderAPI expansions of all ten plugins

Variables use the %name% syntax. Numeric expressions require variables to resolve to numbers; text templates convert variables to strings. Do not treat an internal template variable or PlaceholderAPI placeholder as a formula variable unless that formula context explicitly provides it

Numeric expressions ​

CoreLib uses exp4j for numeric expressions and registers several helper functions

TypeSupported syntax
Operators+, -, *, /, %, ^, parentheses
One-argument functionsceil(x), floor(x), round(x), log10(x)
Two-argument functionsmin(a,b), max(a,b), pow(a,b)
yaml
economy:
  enabled: true
  base_cost: 100
  cost_formula: '100 + %star% * 50'
yaml
quality:
  chance_formula: 'min(0.95, 0.05 + %material_score% * 0.001)'

Numeric expressions are limited for safety:

  • Maximum expression length is 256 characters
  • Maximum nested evaluation depth is 10
  • Backticks, dollar signs, and backslashes are not allowed
  • After variables are resolved, a numeric expression may only contain numbers, whitespace, operators, parentheses, commas, and supported function names
  • Results must not be NaN or infinite

Boolean expressions ​

You will meet boolean expressions in conditions, pipeline if branches, and random-text switches

Truthy literals: true, yes, y, on, 1

Falsy literals: false, no, n, off, 0

OperationExample
Numeric comparison%level% >= 10, %score% < 100
String equality"forge" == "forge", %phase% != "fail"
AND%level% >= 10 && %money% >= 100
OR`%rarity% == "rare"
NOT!%locked%, !(%level% < 10)
Parentheses`(%a% > 0 && %b% > 0)

String comparisons should be quoted to avoid numeric-expression ambiguity

yaml
condition:
  entries:
    - type: expression
      expression: '%player_level% >= 20 && %money% >= 1000'

Text templates ​

Text evaluation replaces %name% variables with string values

yaml
message: 'Current level: %level%, next cost: %next_cost%'

Missing text variables are replaced with an empty string and reported in detailed evaluation results. Numbers are formatted compactly: integer values are shown as integers, and decimals are shortened

You can also write it in object form:

yaml
name:
  type: string
  value: 'Lv.%level% Stone'

type accepts only these two literals, with no aliases:

TypeAccepted value
Stringstring
Booleanboolean

str, text, bool, and flag are not recognised; such a config falls into the parse-failure branch

Random numeric configs ​

Numeric fields can also be written as random config objects

Range shorthand ​

A string in the form min~max means uniform random:

yaml
reward_amount: '10 ~ 20'

Both sides can be expressions:

yaml
reward_amount: '%level% * 5 ~ %level% * 8'

Local variables ​

Random config objects may define local variables:

yaml
amount:
  type: expression
  variables:
    base: 100
    bonus: '%level% * 5'
  value: '%base% + %bonus%'

variables extend or override outer variables for the current config and its children

Supported numeric config types ​

TypeAliasesFieldsDescription
constant-valueFixed value
range-value or min + maxUses value if present; otherwise behaves like uniform
uniform-min, maxUniform random in [min,max]
gaussian-optional mean, std_dev, min, max, max_attemptsNormal distribution. Defaults derive from min/max when possible
skew_normal-same as gaussian, plus skewnessSkew-normal distribution. skewness defaults to 0
triangle-optional mode, deviationTriangle distribution. Defaults: mode=0, deviation=1
expression-valueNumeric expression
yaml
bonus:
  type: uniform
  min: 5
  max: '10 + %level%'
yaml
quality_score:
  type: gaussian
  min: 0
  max: 100
  mean: '50 + %material_quality% * 5'
  std_dev: 12
  max_attempts: 128

If type is missing, CoreLib tries to infer the config:

  1. value exists: evaluate value
  2. min and max exist: treat as uniform
  3. Otherwise the config is unsupported

The expression field is only read when type: expression; writing expression: on its own without a type is not inferred as a numeric config

Random text configs ​

Text configs pick one or more candidates at random. Supported types:

  • random_text
  • random_text_lines
  • random_lines
  • random_line
  • text_lines

Candidate field: lines

FieldAliasesDefaultDescription
count-1Number of selected lines. Can be a numeric expression or random numeric config
allow_duplicates-falseWhether the same candidate can be selected multiple times
separator-newlineSeparator used when joining multiple results
yaml
message:
  type: random_text
  count: 1
  lines:
    - '<green>Forge success!</green>'
    - '<gold>Sparks fly as the item takes shape.</gold>'
    - '<aqua>%player_name% created a masterpiece.</aqua>'

Quantity configs ​

Fields that need "a number worked out per situation" — costs, chances, capacities, experience — can also be written as a quantity config object, in addition to plain formulas and random configs. Three types are supported

Fixed ​

yaml
quantity: 100

The equivalent long form:

yaml
quantity:
  type: fixed
  value: 100

Formula ​

yaml
quantity:
  type: formula
  expression: "player_level * 10 + 50"

Lookup table ​

Looks up the integer value of a variable, falling back to default on a miss:

yaml
quantity:
  type: lookup_table
  key: player_level
  default: 0
  table:
    1: 10
    2: 20
    5: 50
FieldTypeRequiredDefaultRangeDescription
typestringNofixedfixed, formula, lookup_table (alias table)Quantity config type; an unknown value degrades to fixed
valuenumberNo0a number or numeric expressionThe value used by fixed
expressionstringNo"0"CoreLib numeric expressionThe formula used by formula
keystringNoplayer_levelvariable nameVariable name the lookup table reads
defaultnumberNo0a numberValue used when the lookup table misses
tablesectionNoemptyinteger-key to number mappingEntries whose key is not an integer are skipped

An invalid form does not raise an error; it degrades in this order:

  • A plain number or numeric string is treated as fixed
  • A config section is parsed by type; an unknown type degrades to fixed and reads value
  • Blank or absent becomes fixed(0)

Cron expressions ​

A cron field uses the 6-field Quartz format and fires on real system time, not game ticks:

second minute hour day-of-month month day-of-week

*, ? (equivalent to *), literal values, , enumerations, - ranges, and / steps are supported

"0 0 19 * * ?"        every day at 19:00:00
"0 30 8 ? * MON-FRI"  weekdays at 08:30:00
"0 0/15 * * * *"      every 15 minutes

If no next fire time exists within 4 years, the task is not scheduled. An invalid expression skips only that task and leaves a console warning; the rest of the plugin is unaffected

cron is used by EmakiMobs spawn rules (type: autonomous with trigger: cron) and by scheduled EmakiSkills passive skills

Random char configs ​

Text configs also support three families of random char types. They share the count, allow_duplicates, and separator control fields with the same meaning as random text configs

TypeAliasesCandidate field
random_charrandom_chars, char_random, chars_randomchars
weighted_random_charweighted_random_chars, weighted_char, weighted_chars, weighted_char_randomchars
conditional_charcondition_char, case_char, if_charcases

When chars is omitted, abcdefghijklmnopqrstuvwxyz is used

yaml
suffix:
  type: random_char
  count: 3
  chars: 'ABCDEF'

conditional_char evaluates the condition of each entry in cases in order and returns the value of the first one that is true. If none match, it returns fallback, or an empty string when fallback is absent

yaml
grade_mark:
  type: conditional_char
  cases:
    - condition: '%level% >= 50'
      value: 'S'
    - condition: '%level% >= 20'
      value: 'A'
  fallback: 'B'

YAML tips ​

  • Quote expressions containing >, <, :, {}, %, #, &, or *
  • Verify whether a module expects chance values as 0~1 or 0~100; the pipeline chance gate supports both decimals and percent notation
  • Clamp money, amount, and level formulas with max(0, value) when negative values are invalid
  • Random configs can nest, but nested evaluation depth is limited to 10

Troubleshooting ​

Expression cannot be parsed ​

Common causes:

  • Mismatched parentheses
  • Missing or misspelled variables
  • Unsupported functions
  • Disallowed characters such as backticks, dollar signs, or backslashes
  • Unquoted YAML strings containing special characters

Result is unexpected ​

Check the actual variables injected by the current module, integer vs decimal behavior, percentage conventions, clamping or rounding logic, and whether string comparisons are quoted

Random config always returns 0 ​

Common causes include a misspelled type, missing min / max for uniform, missing value for expression configs, or nested variables that cannot resolve to numbers