-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to get the last element of an array using negative indices in ARRAY.slice() #61530
Comments
To obtain the last element you just omit the second parameter so it will default to
Current description in the docs correctly explains this behavior: Lines 445 to 458 in 823f1d3
|
Granted, the docs do explain it, but in a fairly opaque way that isn't obvious to amateurs like myself, relying on some understanding of how slice() works. It's really not easy to understand that a negative index will return the right side of an array. Here is my proposed revision of the docs:
New text is encapsulated by ** |
There's indeed a flaw in the design but for the opposite case: currently when slicing with a negative step it's impossible to make the slice include the first element of the array (see #79103 (comment)). Marking this as a bug. |
Godot version
Godot 4 alpha 8
System information
Windows 11, Surface pro
Issue description
It is currently impossible to return the last element of an array using Array.slice, when using negative indices. When you try, it silently fails and returns an empty array. Consequently, using Array.slice on an array with a single element is impossible.
Presumably, using arr.slice(-1,0) would return the final value of an array, but it does not.
Expected output:
Actual output:
Steps to reproduce
See above.
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: