egametang/ET · error · Exception

condition variable not registered: {variable}

Error message

condition variable not registered: {variable}

What it means

Thrown by ConditionExprParser.ParseCompare when the variable name extracted from the expression is not found in ConditionVariableRegistry. The registry maps variable names to node types: all NumericType enum names are auto-registered to BTNumericCompare, plus any [ConditionVariable]-attributed BTCondition. An unknown variable means the name is misspelled, unregistered, or not a NumericType.

Source

Thrown at Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprParser.cs:124

            this.ReadVariable(variableToken.Text, out string ownerKey, out string variable, out bool hasOwnerKey);
            string[] paramValues = this.ReadParams(out bool hasParams);
            ConditionCompareOp op = this.ReadCompareOp();
            ConditionToken valueToken = this.Expect(ConditionTokenType.Number);
            int errorCode = this.defaultErrorCode;
            if (this.Match(ConditionTokenType.Colon))
            {
                errorCode = this.ReadErrorCode();
            }

            ConditionVariableRegistry registry = ConditionVariableRegistry.Instance;
            if (registry == null)
            {
                throw new Exception("condition variable registry is not initialized");
            }

            if (!registry.TryGetNodeType(variable, out Type nodeType))
            {
                throw new Exception($"condition variable not registered: {variable}");
            }

            BTCondition node = Activator.CreateInstance(nodeType) as BTCondition;
            if (node == null)
            {
                throw new Exception($"condition variable node create error: {nodeType.FullName}");
            }

            node.Id = this.NextNodeId();
            if (node is BTNumericCompare numericCompare)
            {
                if (hasParams)
                {
                    this.SetParamsField(numericCompare, paramValues);
                }

                if (registry.TryGetNumericType(variable, out NumericType numericType))
                {

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Check the variable name spelling in the expression against registered names (NumericType enum values and [ConditionVariable] names).
  2. If it is a numeric property, confirm the name matches a NumericType enum member exactly.
  3. If it is a custom node, add [ConditionVariable("Name")] to the BTCondition subclass so it registers at startup.
  4. Log ConditionVariableRegistry contents at startup to see all registered names for comparison.

Example fix

// before (expression cell)
//   Mana > 50     // 'Mana' is not a NumericType and no [ConditionVariable]
// after
//   Mp > 50        // 'Mp' is an existing NumericType (matches the enum)
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on an expression, confirm each variable resolves:
ConditionVariableRegistry.Instance.TryGetNodeType(variable, out _); // false -> unregistered

Type guard

static bool IsRegisteredVariable(string v) =>
    ConditionVariableRegistry.Instance != null &&
    ConditionVariableRegistry.Instance.TryGetNodeType(v, out _);

Prevention

When it happens

Trigger: An expression like 'Mana > 50' where 'Mana' is neither a NumericType enum value nor a [ConditionVariable("Mana")] node; a typo such as 'H' instead of 'HP'; referencing a numeric type that was removed from the NumericType enum.

Common situations: Typo in the variable name in the Luban/Excel cell; the variable's NumericType was renamed/removed; a custom condition node is missing its [ConditionVariable] attribute so it never registered.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/11e19fef108cfdec. Report an issue: GitHub.