I know it's possible to slice an array in python by array[2:4]. The way I get around this is to just loop through the indexes I want and append them to the new_list. This way requires more work is there just a simple way to do it like in python?
Asked
Active
Viewed 4,290 times
1 Answers
9
You can use the Array.slice() method added in Godot 3.2 for this purpose:
Array slice ( int begin, int end, int step=1, bool deep=False )
Duplicates the subset described in the function and returns it in an array, deeply copying the array if
deepistrue. Lower and upper index are inclusive, with thestepdescribing the change between indices while slicing.
Example:
var array = [2, 4, 6, 8]
var subset = array.slice(1, 2)
print(subset) # Should print [4, 6]
-
Thanks It works perfectly, I still need to learn the 3.2 features – jujumumu Feb 14 '20 at 02:55