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
- Use exactly one dot in the form 'OwnerKey.Variable'.
- Remove leading/trailing dots from the variable token.
- Do not attempt multi-level dotted paths; flatten to a single registered variable name.
- 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
- Use only single-level 'OwnerKey.Variable' references.
- Avoid leading/trailing dots and nested paths.
- Lint dotted references during config import.
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
- condition variable not registered: {variable}
- condition compare op expected, actual: {token.Text}
- condition number parse error: {text}
- condition token error at {this.index}: {c}
- condition variable node create error: {nodeType.FullName}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/5a40a243b57f813e.
Report an issue: GitHub.