Can I use an Array as an Object Name?


so im currently working on a parking game. The goal is to park cars in a car park. To increase the fun, i added different cars, so far so good.

Then i decided, it would be more fun to have the cars to steer appear in a random order and that’s where problems started. After hours of trying, i managed to create an array which is randomly shuffeled by the ArrayTools Extension. To spawn cars, i used the following expression:

The spawn works fine so far, but i can’t adess the car i spawned because its one random car between PlayerCar1 to PlayerCar5. GDevelop doesn’t accept that the name of the object is:


Is there any way to work without a “PlayerCars” Group?

Because when the car was parked, i used to just go to the next car to park it.
Now, i have to delete the car and spawn a new one, which is outside the “PlayerCars” group (to let the parked car stay in the parking lot, signalizing the parking lot is blocked). This is not that easy because when i spawn the new car, the position and angle is wrong. Its just so much more work to do.
Is there any way to use the expression (“PlayerCar”+VariableString(CarSpawn[0])) as the object name or a number (object variable?) or something like that?

Thanks a lot!

If you only need to identify 1 car, you can use an boolean object variable, and use that as a condition when you need to refer to that one car.


Identifying one car with boolean should work fine but it should work like this:

Car 1 Spawns → Player parks car one
Car 2 Spawns → Player parks car two
Car 3 Spawns → Player parks car three
Car 4 Spawns → Player parks car four
Car 5 Spawns → Player parks car five

i’m trying to set the parked car on an other layer, maybe that’ll work out. I don’t know if its possible to make the collision working when the parked cars are on another layer but i’ll try it. Its my first game ^^

After thinking a bit more, it should be way more easy to check, which object spawned at the position than just checking which object spawned at the base layer but i think the object boolean is the way to go.