diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java index b278efe11..f70319d21 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java @@ -1657,6 +1657,11 @@ public class ScriptDocument { return null; } + // Invalid expressions starting with brackets + if (expr.startsWith("[") || expr.startsWith("]")) { + return null; // Invalid syntax + } + // String literals if (expr.startsWith("\"") && expr.endsWith("\"")) { return resolveType("String"); @@ -1809,6 +1814,23 @@ public class ScriptDocument { } } + // Check if followed by array brackets (array access) + // Skip array accesses like [0] or [i] - treat them as part of the current segment + while (i < expr.length() && Character.isWhitespace(expr.charAt(i))) { + i++; + } + if (i < expr.length() && expr.charAt(i) == '[') { + // Skip to the matching closing bracket + int depth = 1; + i++; + while (i < expr.length() && depth > 0) { + char c = expr.charAt(i); + if (c == '[') depth++; + else if (c == ']') depth--; + i++; + } + } + segments.add(new ChainSegment(name, start, i, isMethodCall)); // Skip whitespace