Create objects and join into a list dynamically

Hello.
I want to create 100 cars and put them all in a list.
Does there have any way to join objects in variable into a list?

I hope I can control all of objects by a loop.

2 Likes

Hi @Rata,

Your solution was close! In order to fill your myList - variable, you can use the following block to put the last created car into the list variable (see 1.):

1. show block example

PlaceIntoList

Below is the final code. Note how we create an empty list at the start of the scene, before we iterate through creating cars and storing them in myList (see 2.).

2. show list example

Code in action
CodeInAction

Notice how the cars only drive one after another? That’s because the move item - block only allows the code to continue after the item is done moving. To make all items move at the same time, we can do the following (see 3.):

3. show synchronous example

image

Code in action
CodeInAction2

How it works:
We place the move item - block into the on update - block from the events category. The on update block will repeat all content it has as often as possible.
In this example, however, we stop the block just after the item is done moving.

The on update block itself does not cause the code from the for each - loop to be stopped, which allows us to to quickly go through all items of the list and trigger the moving behaviour.

Hope this helped!

6 Likes

That is what I want to do. Thank you so much !

2 Likes