egametang/ET · error · Exception

condition variable reference invalid: {text}

Error message

condition variable reference invalid: {text}

What it means

Thrown by ConditionExprParser.ReadVariable when an OwnerKey.Variable reference is malformed. The grammar allows exactly one dot separating a registered owner key from a variable (e.g. Unit1.HP). The reference is invalid if the dot is at the start ('.HP'), at the end ('Unit.'), or if there is more than one dot ('A.B.C').

Source

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

            this.SetCompareField(node, nameof(BTNumericCompare.ErrorCode), errorCode);
            return node;
        }

        private void ReadVariable(string text, out string ownerKey, out string variable, out bool hasOwnerKey)
        {
            ownerKey = ConditionExprEnvKeys.Unit;
            variable = text;
            hasOwnerKey = false;

            int dotIndex = text.IndexOf('.');
            if (dotIndex < 0)
            {
                return;
            }

            if (dotIndex == 0 || dotIndex == text.Length - 1 || dotIndex != text.LastIndexOf('.'))
            {
                throw new Exception($"condition variable reference invalid: {text}");
            }

            ownerKey = text.Substring(0, dotIndex);
            variable = text.Substring(dotIndex + 1);
            hasOwnerKey = true;
        }

        private string[] ReadParams(out bool hasParams)
        {
            hasParams = false;
            if (!this.Match(ConditionTokenType.LeftParen))
            {
                return Array.Empty<string>();
            }

            hasParams = true;
            List<string> paramValues = new();
            if (this.Match(ConditionTokenType.RightParen))

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Use exactly one dot in the form 'OwnerKey.Variable'.
  2. Remove leading/trailing dots from the variable token.
  3. Do not attempt multi-level dotted paths; flatten to a single registered variable name.
  4. Confirm OwnerKey is a key previously passed to BTEnv.AddEntity.

Example fix

// before (expression cell)
//   Unit.Sub.HP > 0
// after
//   Unit.HP > 0
Defensive patterns

Strategy: validation

Validate before calling

// Validate variable token shape before parse: a dotted ref must have exactly one dot,
// not at start or end:
int dots = text.Count(c => c == '.');
bool ok = dots == 0 || (dots == 1 && text[0] != '.' && text[^1] != '.');

Type guard

static bool IsValidVariableRef(string text)
{
    int i = text.IndexOf('.');
    return i < 0 || (i > 0 && i < text.Length - 1 && i == text.LastIndexOf('.'));
}

Prevention

When it happens

Trigger: An expression like '.HP > 0' (leading dot), 'Unit. > 0' (trailing dot), or 'Unit.Sub.HP > 0' (two dots). Only a single-level 'OwnerKey.Variable' is permitted.

Common situations: Author attempting nested member access that the grammar does not support; a stray dot typed at the start/end of the variable; copy-paste introducing an extra dot.

Related errors


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