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?
Godot - How do I create a subarray of a list in Gdscript?
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
deep
istrue
. Lower and upper index are inclusive, with thestep
describing 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 –
Conaway
© 2022 - 2024 — McMap. All rights reserved.