var a = []
for i in range(n):
a.append(0) # or a += [0]
Bit disappointed that there’s no such thing, but it’s not a dealbreaker. Thanks.
gax | 2017-09-10 05:48
Agreed, it would be nice, but it’s not a dealbreaker.
Python-style generators would be really nice, too.
kidscancode | 2017-09-10 05:54
As an alternative to doing a for loop, in Godot 3 (at least) you can use the Array’s resize method (if resizing a predefined array with the intention of resetting it, be sure to call the clear() function first):
Too bad there’s no inline way to initialize an Array of n size. Maybe that’ll come down the road as most languages support the feature.
Happy coding!
Smij | 2019-06-15 03:21
The compiler complains that you are declaring ‘i’ but not using it. Again, not a deal breaker, just annoying
W 0:00:27.804 The local variable ‘i’ is declared but never used in the block. If this is intended, prefix it with an underscore: ‘_i’
<C++ Error> UNUSED_VARIABLE