Array Tools: Insert at Index problem

Am I using “Insert variable at index” from Array Tools correctly? When I use it to add an array to a specific index of another (empty) array, it always puts the variable in [0], and creates null values for the indices up to the intended index.

When I do this:
Screenshot 2025-11-12 at 09.04.27

(CurrentLink is 2 in this case)

This happens:

Context:

In my game I have a card “linking” ability, which lets the player drag a card onto another one in their hand, linking them. Each card is represented by a structure, and I keep track of all those structures in an array called Hand.

Now I want an array called LinkedCards to contain all the structures of cards that were linked to another card (and not the ones they were linked to, those stay in Hand), and I want to store them aft the same index of the card in Hand. This way, if two cards have the same index in both arrays, I know they’re linked. I use a temporary array for the card being dragged/dropped.

Example: the player has five cards in hand. The Array Hand will have card structures at indices 0, 1, 2, 3 and 4. Now the player links card 4 to card 2. When I use Insert array at index 2 from the Array Tools extension, the structure is not stored at [2], but at [0]. It does however declare indices up until [2], and fills those with null values.

What am I doing wrong? When I use Slice, for example, to store the array at the desired index, it will do so, but only top-level (ie. just that the stored variable is a structure, but none of its children).

Thanks for any help.

Note: I deleted an older post about this because I realized it was too vaguely described and it wouldn’t let me edit it.

Try using the GDevelop add existing variable action instead.

This action:

image


produces:


Array tools uses this Javascript under the hood. I suspect the Splice bit is the part where it doesn’t quite work:

image

I tried that and as shown in his post, it creates an array at that index. So, you have an array, array, structure

As MrMen said, it seems to be the splice function. Slice doesn’t seem to create indexes, it only slice variables into existing ones.

When I tested it with an empty array it added my variable at index 0 instead of my desired 13. If the array had at least 13 existing elements, it added my variable at index 13.

You could insure the array has enough indexes or use Json.

Example:

This puts the structure name child into Array1 at index 13.

The array tools issue seems like a bug or maybe it’s an oversight. You could put in a bug report or feature request to have it at insert the variable at the target index regardless of whether the element exists in the target array or not.

As for your null elements, my guess is that array tools isn’t creating them. I’m guessing that if you try to add index 13 that the empty index is created when you try to get the child values at index 13. If a variable or element doesn’t exist, GD will create it along with any non-existent previous indexes.

Instead of using the Json line, you could create an extension with it. That way it would make the intention clearer. You could create your own add item function.

1 Like

Thank you both very much… I tried MrMen’s suggestion but unfortunately, it creates a new array as Keith_1357 notes. I will try to implement his other suggestions and report back here. (I’ve only just started out in game dev and it seems I am in a little over my head diving into arrays like this… :sweat_smile:)

Again, thanks for your fast and helpful replies!

1 Like

The JSON idea is quite ingenious and works beautifully… thanks Keith_1357! I had no idea this kind of creativity was ‘allowed’! :wink:

1 Like