babalae/better-genshin-impact · error · InvalidOperationException

未知条件函数:{name}

Error message

未知条件函数:{name}

What it means

Thrown by ConditionEvaluator.EvalFunc when a function call's name does not match any of the built-in condition functions (last-exec, q-ready, e-ready, e-cd, low-hp, battle-time, in-party, onfield, t, since, count, min, max, last-check). The function name is lowercased before matching, so case differences are not the issue — the name itself is unrecognized. When called via Evaluate(), this is caught internally and Evaluate returns false.

Source

Thrown at BetterGenshinImpact/GameTask/AutoFight/Script/ConditionEvaluator.cs:456

        // 函数名大小写不敏感(min/MIN、MAX/max 均可)
        name = name.ToLowerInvariant();
        return name switch
        {
            "last-exec" => EvalLastExec(args, currentIndex),
            "q-ready" => EvalQReady(args),
            "e-ready" => EvalEReady(args),
            "e-cd" => EvalECd(args),
            "low-hp" => EvalLowHp(),
            "battle-time" => EvalBattleTime(args),
            "in-party" => EvalInParty(args),
            "onfield" => EvalOnField(),
            "t" => EvalT(),
            "since" => EvalSince(args, currentIndex),
            "count" => EvalCount(args, currentIndex),
            "min" => EvalMinMax(args, currentIndex, isMax: false),
            "max" => EvalMinMax(args, currentIndex, isMax: true),
            "last-check" => EvalLastCheck(),
            _ => throw new InvalidOperationException($"未知条件函数:{name}")
        };
    }

    // ========== 类型转换 ==========

    /// <summary>将对象转换为 bool</summary>
    private static bool ToBool(object val)
    {
        return val switch
        {
            bool b => b,
            double d => d > 0,
            _ => false
        };
    }

    /// <summary>将对象转换为 double</summary>
    private static double ToNumber(object val)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Check the function name in the error message ({name}) against the supported list.
  2. Fix typos in function names (e.g., 'q-ready' not 'q_reday', 'low-hp' not 'lowhp').
  3. If referencing an action by name, ensure the action is declared in the strategy's Actions list.
  4. Refer to the supported functions documented in the ConditionEvaluator class header.

Example fix

// before (typo in function name)
"condition": "q_reday()"

// after
"condition": "q-ready()"
Defensive patterns

Strategy: validation

Validate before calling

// Validate function names against the known set before evaluation
static readonly HashSet<string> KnownFunctions = ConditionEvaluator.FunctionNames;

static bool UsesOnlyKnownFunctions(string expr, HashSet<string> actionNames)
{
    // Extract function-call names and check each
    var tokens = expr.Split([' ', '(', ')', ',', '!', '&', '|', '+', '-', '*', '/', '<', '>', '='],
                           StringSplitOptions.RemoveEmptyEntries);
    foreach (var t in tokens)
    {
        if (!char.IsLetter(t[0])) continue;
        if (t is "true" or "false") continue;
        if (double.TryParse(t, out _)) continue;
        if (!KnownFunctions.Contains(t) && !actionNames.Contains(t))
            return false;
    }
    return true;
}

Try / catch

// Evaluate catches this internally and returns false.
// The warning log includes the expression and the unknown function name.
// Check logs for '条件表达式求值失败' with '未知条件函数' in the message.

Prevention

When it happens

Trigger: A condition expression calls a function whose name is not in the built-in function list and is not a declared action name used as a zero-arg function reference. For example: `hp-ready()` (not a real function), `energy(>5)`, or a typo like `q_reday()`.

Common situations: User misspells a built-in function name, invents a function that doesn't exist, or references an action name that wasn't declared in the strategy. The grammar allows bare identifiers to be treated as zero-arg function calls, so any unknown name reaches EvalFunc and fails here.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/9ecb7ade597e9e6c. Report an issue: GitHub.