Controlled randomization

I am brand new to Gdevelop, and was wondering if I could have an inventory of different sprites and make it so when the new scene opens, they all go randomly into pre selected coordinates? Also can I have over 24 options in the inventory, but only have 24 of them spawn when the new scene is opened. There are only 24 positions I want them to spawn in, but I want it different each time someone plays, meaning there would be around 50 different sprites that have the chance of spawning.

Hi, I am not sure if anyone will give you a solution out of the box. There is a good pairs-example that is doing what you want: assigning sprites randomly to a specific position on a board (which could be as in your case an inventory) GDevelop 5.

It is actually quite easy:

  1. You put all your item-sprites for the inventory in a group (if 50 or more is up to you).
  2. The pairs-example has placeholder sprites on the board which are used as reference for placing the items. Then with help of a ‘Repeat for each instance of “placeholder”’ - event each placeholder is chosen and replaced with an inventory sprite.
  3. The random placement of the inventory sprites is easily possible through the “Pick a random object”-condition which you can use on your inventory sprite-group (see no. 1).

I am not sure if this helps you to achieve all you want, but it could get you started.

An alternative to @Drona’s point 2 is to instead create an array variable and add your predefined position coordinates in there. Then just loop through it and create random objects at each position.

If I am not misunderstood you want to have random sprite for your object?

Because I don’t know the object and sprite etc, here is an example:

  1. Create object called ‘fruits’, add an animation called ‘apple’ then add apple.png. Repeat it again but this time for Orange and grape.
  2. Put your ‘fruits’ on the desired position, you can put a lot of them.
  3. Add variable to it (string) called ‘fruitName’.
  4. For the code: At the beginning of the scene - change the text variable ‘fruitName’ of ‘fruits’ set to Choose::RandomString(“apple,orange,grape”).
  5. Set animation of ‘fruits’ to 'fruits.VariableString(fruitname).

To use RandomString you need to download an extension called ‘Choose’, or you could just use randomNumber to randomly generate sprite.

Sorry if my english and explanation is not good.