Listing and spawning objects from Array

I am still trying to figure out GDevelop workflow, but here is what I want to do:

At the beginning of the scene I would like to randomly spawn 4 objects at the time, listed in array, out of 10. And then to delete from that array the ones that were spawned…

So, I would first make 10 objects/sprites, and then make one control object that has array variable that contains 10 children (fields), and their value would be the same name (string) as 10 objects/sprites previously created?

Then at the beginning of the scene I need to make event to Create an object from its name, and as a name to use random number (converted to string) from the total amount of fields in the array from control object?

Is there any command/function that will automatically calculate total number of fields from the selected array?

After spawning objects based on name of fields in array, how can I delete (pop) those used fields, so I can use another action that will spawn four more random objects based on 6 left from same array?

Do you want to create 4 objects out of 10? You could create the 10 and remove 6 of them at random.

yes, or, to create random 2 (out of 10), and then again 2, and so on, until all 10 are created. But the thing is, with random spawning I want to avoid possibility to have duplicates. In order to do that I can only think of putting all 10 object names in the array and to remove them moment they are spawned.

I just did something similar, not exactly the same, but I have 14 items I can choose to spawn, I want to only spawn one at a time, but once it is collected by the player, not respawn that one. Info is housed in variable array with a structure for each array including 4 children, one being a true/false boolean which was the key to checking. Here is my code of what I did, maybe it helps spawn some ideas to prevent duplicates , because it prevented any duplicates from spawning in my game. BTW, I housed all items as 1 object, but with multiple animations:

hope that may help :slight_smile:

This uses an array to store the numbers with the added bonus of refilling the array if all of the numbers are chosen. I added some events to arrange the sprites to make sure it was working.

My project:
doug13579/Gdevelop-create-a-number-of-objects-from-a-group-without-repeating-them (github.com)

Click the screen to create 4 random objects

1 Like

This extension can shuffle objects:
https://wiki.gdevelop.io/gdevelop5/extensions/object-stack/reference

This extension can shuffle values:
https://wiki.gdevelop.io/gdevelop5/extensions/array-tools/reference

1 Like

Thanks guys, it helps a lot to see your way of solving similar challenge.

I am surprised that Array tool is not available natively inside the engine, but instead its a downloadable extension.