I’ve tried to create a feature in many different ways, but I can’t get it to work.
I randomly generate “clients” objects in batches of 1 to 4 (randomly). They are linked by a “GroupId” variable. When I click on a group and then click on a “table” element, they are supposed to move around the table.
Currently, they all move to the same side of the table, that’s not what I want.
I’ve tried several things. For example:
• Creating a variable that I increment with each client processed, but I couldn’t manage to handle them one by one.
• Assigning IDs to each client, grouping the 4 IDs in an array, looping through all instances and selecting those with the relevant IDs, but I couldn’t add a condition on the value of the child in the array’s for each loop to say “if the ID = the first in the array, go here, if it’s the 2nd, go here,” etc.
Here is an example I tested (the first line of the 4 was the start of a new technique, but I didn’t manage to finish):
Conditions pick objects. They’re like filters. If client objects exist then you need a way to pick just one at a time, otherwise all of the client objects will be used with the actions. I added a bunch of Tables and Clients to the scene.
In this example, I gave the table and client objects a Boolean variable name “IsFree” and set it to True.
When a table is clicked, the table is marked as free = false, it then uses the repeat event to repeat a random number of times between 1 and 4, It uses a Counter scene variable to choose a spot.
It chooses a client by first picking the client objects whose IsFree variable is True. It then picks a random Client from that list. It then moves the picked client and sets its IsFree variable to False. So, it won’t be picked again.
If the clients weren’t already in the scene, you could create them right before you did the move events. New objects are picked automatically, so any actions would apply to the new object as long as it was in the same event or a subevent.
Here’s an example using an object named SpawnPoint as the reference point to add Clients.
There are infinite ways to do things. They can be discussed but it’s important to understand why something doesn’t work first. You need to learn the process, the fundamentals.
Thank you very much for your help, it makes sense! I’ve been learning GDevelop for a week and find it very impressive. I used to code everything myself, so now I just need to go further in understanding the logic.