babalae/better-genshin-impact · error · ArgumentException
策略字符串不能为空
Error message
策略字符串不能为空
What it means
ArgumentException thrown by RunCombatScript at line 390 when the `script` string is null, empty, or whitespace. The combat script is a DSL parsed by CombatScriptParser.ParseContext (e.g. 'e,q,attack'); an empty script has nothing to execute and the parser would error, so the guard rejects it early. Note this is ArgumentException, not ArgumentNullException, because it uses IsNullOrWhiteSpace.
Solutions
- Pass a non-empty combat script string with at least one command (e.g. 'e,q,attack').
- Validate the string is non-whitespace in JS before calling.
- If the script is optional, skip the call entirely rather than passing empty.
Example fix
// before (JS)
dispatcher.RunCombatScript(script); // script is '' -> throws
// after (JS)
if (script && script.trim()) {
dispatcher.RunCombatScript(script);
} Defensive patterns
Strategy: validation
Validate before calling
// JS side
if (script == null || String(script).trim() === '') throw new Error('combat script string is required');
dispatcher.RunCombatScript(script); Prevention
- Pass a non-empty combat script with at least one command.
- Skip the call entirely for optional/empty scripts rather than passing empty.
- Validate loaded script files are non-empty before invoking.
When it happens
Trigger: JS calls `dispatcher.RunCombatScript('')`, `RunCombatScript(null)`, or `RunCombatScript(' ')`. A script variable loaded from an empty file or unset config.
Common situations: Author left the script string empty as a placeholder. A file read returned empty. Whitespace-only content from a template.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/6f6c9ba4821370b1.
Report an issue: GitHub.
Appendix: source
Thrown at BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs:390
CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;
var factory = GameTask.AutoFight.Factory.CombatTaskFactoryProvider.GetFactory(param.CombatStrategyPath);
var fightTask = factory.CreateTask(param);
await fightTask.Start(cancellationToken);
}
/// <summary>
/// 运行简易战斗策略脚本。
/// 使用策略语言直接控制角色执行动作(如 e、q、attack 等),适合快速操作。
/// </summary>
/// <param name="script">策略字符串,支持逗号/换行/分号分隔指令,可选角色名前缀</param>
/// <param name="avatarName">指定操作的角色名(可选,不指定则操作当前角色)</param>
/// <param name="customCt">自定义取消令牌</param>
public async Task RunCombatScript(string script, string? avatarName = null, CancellationToken? customCt = null)
{
if (string.IsNullOrWhiteSpace(script))
{
throw new ArgumentException("策略字符串不能为空", nameof(script));
}
CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;
// 1. 解析策略字符串(ParseContext 已处理全角符号、注释、分号/逗号分隔)
var combatScript = CombatScriptParser.ParseContext(script, validate: false, defaultAvatarName: avatarName);
if (combatScript.CombatCommands.Count == 0) return;
_logger.LogInformation("执行 {Text}", "简易策略脚本");
await CombatScriptExecutor.ExecuteAsync(combatScript, cancellationToken, _logger);
}
/// <summary>
/// 运行自动地脉花任务
/// </summary>
/// <param name="param">自动地脉花任务参数</param>
/// <param name="customCt">自定义取消令牌</param> View on GitHub (pinned to a7cb36712d)