babalae/better-genshin-impact · error · Exception
战斗脚本格式错误,指令括号不完整
Error message
战斗脚本格式错误,指令括号不完整
What it means
Thrown by CombatScriptParser.ParseLinePart after the comma-merge loop exhausts all remaining fragments without ever finding a ')' to close the opening '('. The command started with '(' but no ')' was found in any subsequent comma-separated fragment, so the parser cannot form a complete command and aborts.
Source
Thrown at BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptParser.cs:261
if (command.Count("(".Contains) > 1)
{
Logger.LogError("战斗脚本格式错误,指令 {Cmd} 括号无法配对", command);
throw new Exception("战斗脚本格式错误,指令括号无法配对");
}
if (command.Contains(')'))
{
i = j;
break;
}
j++;
}
if (!(command.Contains('(') && command.Contains(')')))
{
Logger.LogError("战斗脚本格式错误,指令 {Cmd} 括号不完整", command);
throw new Exception("战斗脚本格式错误,指令括号不完整");
}
}
var combatCommand = new CombatCommand(avatarName, command);
oneLineCombatCommands.Add(combatCommand);
}
return oneLineCombatCommands;
}
}View on GitHub (pinned to a7cb36712d)
Solutions
- Check the logged {Cmd} to see exactly which command is missing its ')'.
- Add the missing ')' at the end of the command.
- If using '|' to separate action groups, ensure each group is fully closed before the '|'.
- Use the JSON strategy format which has structural validation and better error messages.
Example fix
// before (missing closing paren) // 香菱 skill(1,e(2) // after // 香菱 skill(1),e(2)
Defensive patterns
Strategy: validation
Validate before calling
// Check that every '(' has a matching ')' in each pipe-separated segment
static bool AllSegmentsClosed(string line)
{
foreach (var segment in line.Split('|', StringSplitOptions.RemoveEmptyEntries))
{
var open = segment.Count(c => c == '(');
var close = segment.Count(c => c == ')');
if (open != close) return false;
}
return true;
} Try / catch
try
{
var script = CombatScriptParser.ParseContext(text);
}
catch (Exception e) when (e.Message.Contains("括号不完整"))
{
Logger.LogWarning("战斗脚本括号不完整,缺少右括号:{Msg}", e.Message);
} Prevention
- After editing a script, do a quick parenthesis count — every '(' must have a ')'.
- Pay special attention to the last command on each line — that is where ')' is most commonly forgotten.
- Use the JSON strategy format for better structural validation and error messages.
When it happens
Trigger: A TXT combat script line where a command token starts with '(' but the line ends (or the '|' separator is hit after splitting) before a ')' appears. For example: `香菱 skill(1,e(2)` — the last ')' is missing, or `香菱 walk(s, 0.2` where the closing ')' was accidentally deleted.
Common situations: User edits a combat script and accidentally deletes a ')', or a copy-paste truncates the line. Also possible when '|' separators are used mid-parenthesis, causing the split to isolate an unclosed fragment.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/7b143b5793915393.
Report an issue: GitHub.