Create an automatic enemy wave

Hi, I’m using the object spawner extension and I would like to create enemy waves.
I have 18 different enemy types and I would need to create an automatism where enemies are created every 10 seconds and added every time the timer is reset.
I noticed that adding the group of enemies always creates the first enemy so I have to add enemies manually every time the wave number goes up.
Have any of you already used this behavior to give me some advice?

Disclaimer - I haven’t used the spawner extension. However, as a thought, instead of spawning nemici, spawn a nemici placeholder. Then create a random nemici based on the wave number.

If you name the nemici so they are suffixed with a number (so nemici_0, nemici_1…nemici_17), then you can randomly generate a nemici at the placeholder position by using the “Create an object from its name” and the name as "nemici_" + ToString(Random(wave_number))

1 Like

the enemies are numbered and this is what I used previously but I would prefer to give an order to the waves starting with enemy 1 and then moving on to enemies 2 etc… increasing the number of enemies each time.

an example of what I would like to create is:
wave 1 -create 3 enemies1
wave 2 -create 5 enemies1 +2 enemies2
wave 3- create 7 enemies1 + 4 enemies2 + 2 enemies3

reaching up to enemy 18 and then just adding the quantities

I would put those details into an array of structures, so the array index is the wave-1 value, and the children are structures with the key being the enemy name and the value the number of these enemies to spawn.

And then once it gets to wave 18, have the number of enemies calculated by rules set out in events.

1 Like

Hi Jeroen,
is this what you mean? create an array with structures with the name of the enemy to generate and the initial quantity?

I guess I should abandon the object spawner extension since I have no way to insert a variable but only an object

I was thinking more like this:

because then you can simply do:

(but at the spawner position, not those random co-ordinates).

OK I understand how you want to handle it
the enemy_name variable is not recognized and I don’t understand where to apply it
these are my events

To use the variable name without wrapping up with “VariableString()”, define it as a scene string variable in the scene editor.

A few corrections::

  1. don’t use variable Wave as the name for the array and the wave number. Using it to track the wave number will delete the array contents. To track the wave number, use a differently named variable (like wave_number, so it describes what it’s for).

  2. the repeat is for each child of Wave[wave_number] - so all the children that describe the wave enemies.

  3. Indent the repeat so it’s a child of the Timer check event. Otherwise it’ll get run every frame.

1 Like

forgive my ignorance but I’m a bit confused, I created a wave_number string variable, put repeat as a sub-event of the timer but I don’t understand how to create enemies without inserting the name into the array… do I have to create groups?

Instead of for every child in wave
You need for every child in wave[wave_number]
And bc it’s an array wave_number needs be a number not a string.

As is, it only getting the children of wave which would be the array 0, 1 and 2. Since it’s an array of structures it’s getting the structures.

To get the values, you need to choose one of the wave variables children or elements.

Hi guys, I’ve made a few attempts but I think I’m totally confused… please help me!

Edit: I’m not sure why yours isn’t working. Do you have those object names in a group?

I get confused with structures and for each child as well. I̶ t̶h̶i̶n̶k̶ y̶o̶u̶ n̶e̶d̶ t̶o̶ r̶e̶v̶e̶r̶s̶e̶ t̶h̶e̶ l̶a̶s̶t̶ 2̶ v̶a̶r̶i̶a̶b̶l̶e̶s̶ i̶n̶ t̶h̶e̶ ̶̶f̶o̶r̶ e̶a̶c̶h̶ c̶h̶i̶l̶d̶̶̶. I tend to leave the variables as child and childname. That works for me. You can also check the debugger for the last value or add a debug action to display the values. I like to use a text object.

Here’s an example I threw together using fruit.

project: (click the green [code] button and select [download zip] unzip and open the JSON file)




objects and group

1 Like

hi @Keith_1357 thanks so much for sharing your example everything works now!

1 Like