Quick answer: Godot String.substr(from, count) raising an out-of-range error or returning unexpected results? The second argument is a count, not an end index — mixing the two cuts off too much or errors.

Code translated from Python uses str.substr(2, 5) expecting characters 2-5 inclusive; Godot returns 5 characters starting at index 2 (indices 2-6).

Count Not End

my_str.substr(2, 3)  # indices 2, 3, 4

Different from Python s[2:5] which is also 3 characters but expressed as start+stop. Translate carefully.

Omit Count for Rest

substr(from) returns from index to end of string. Used for trimming a known prefix.

Bounds Check

Passing a negative from or one beyond the string length raises an error in some Godot versions. Always validate index against length().

StringName vs String

StringName has no substr. Convert to String first if you need substring operations.

Verifying

Substring extractions return the expected characters. Edge cases (empty string, index at length) handled cleanly.

“Godot substr is start + count, not start + end. Different from Python.”

Write a small wrapper that mimics Python’s slicing if your code base translates often — saves recurring index-math headaches.