-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Array.slice
has an off-by-one error
#72027
Comments
var a = [1,2,3,4,5,6,7,8,9]
print(a.slice(0, len(a)-1)) Also prints |
To get the correct result you have to now do: var a = [1,2,3,4,5,6,7,8,9]
print(a.slice(0, len(a))) However, negative slices are not working as expected. |
I think this is how it should work? As noted by class reference:
So the ending index is not included in resulting array. As you noted, these are the same:
Which return whole array except for the last element (index of which is |
This is the intended behaviour I believe. |
Perhaps we should note in the docs somewhere that this has been updated. It took a while to track down this change when upgrading to 4.x |
I too have pondered on how to know all the changes in Godot 4. |
This is the fourth (fifth?) time I've tried to upgrade my main project to Godot 4.x and I can see the amount of hard work that has gone into it. There are a few niggling issues but in general I was excited and impressed to see that it took less than two hours to get it to render again. Perhaps however a migration guide, which contains such things in an easy to read format could be helpful for users who will upgrade. |
Perhaps the migration tool could add a I usually calculate indexes and so I doubt the tool could resolve it correctly unless using ChatGPT 😂 However a small TODO note would be very much appreciated and it would only apply to older projects as the upgrade tool would be working on them anyway. |
Godot version
v4.0.beta14.official [28a2463]
System information
Mac
Issue description
The above should include nine, but instead prints:
[1, 2, 3, 4, 5, 6, 7, 8]
Steps to reproduce
Minimal reproduction project
N/a
The text was updated successfully, but these errors were encountered: