You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can easily remove the +1 but then the question is how to make it easy to go from begin to the size of the original array without repeating arr.size().
Making the end argument optional like in JavaScript could be an option, but I'm not sure it's easily doable in GDScript. Aside from turning the int end into Variant end, we can't easily make it null or use another state to indicate the "go to size()" function. 0 would be a valid end for an empty slice, and -1 should behave like size() - 1 (wraps around).
And binding a slice(int begin) method is not possible either without polymorphism AFAIK.
After discussion with @KoBeWi and @timothyqiu, it seems like making the function more permissive on possible values for begin and end and giving end a default of INT_MAX could do the trick:
<KoBeWi> we could use something like INT_MAX for default argument. It's unlikely someone will need it
<timothyqiu> `arr.slice()` is also different from Python and JS slices when `end` is greater than the array size + 1. In Python/JS, it means the end of array. While in GDScript it fails.
<Akien> Hm if we combine both comments then `INT_MAX` sounds like an option.
I'll give this a try and make a draft PR, we'll see if it's a good idea.
Godot version
4.0.dev (d746475)
System information
Linux, Mageia 9 x86_64
Issue description
Follow-up to PR #35901 and issue #53495.
The behavior of the negative
end
parameter forArray.slice()
seems inconsistent with how it behaves in other languages. Our implementation uses:And this
+ 1
adds an inconsistency with other implementations.GDScript
prints:
Python / numpy
prints:
JavaScript
prints:
We can easily remove the
+1
but then the question is how to make it easy to go frombegin
to the size of the original array without repeatingarr.size()
.Making the
end
argument optional like in JavaScript could be an option, but I'm not sure it's easily doable in GDScript. Aside from turning theint end
intoVariant end
, we can't easily make itnull
or use another state to indicate the "go to size()" function.0
would be a validend
for an empty slice, and-1
should behave likesize() - 1
(wraps around).And binding a
slice(int begin)
method is not possible either without polymorphism AFAIK.Steps to reproduce
Expected:
but got:
Minimal reproduction project
See above.
The text was updated successfully, but these errors were encountered: