The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm trying to add two items to an array at the same time, so I tried to use the .extend feature like in Python only to realize that this is not supported in Godot. Any suggestions?

in Engine by (46 points)

1 Answer

+1 vote

It's like you said, the Array class does not offer an 'extend' method or something comparable (it does provide '.append' though). You can however concatenate array by simply using the '+' operator, just like in Python.

array1 += [2, 3]

'array1' will now contain the values '2' and '3' at its back. Now this isn't technically the same (I believe) since GDScript will actually create a new Array from the two existing and then set array1 equal to that new one. Python's 'extend' method modifies the first Array directly.
I don't think this will matter though in most cases.

by (305 points)

Pool arrays can be used too, if one of the available types is enough.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.