Add value for every enemy created

HI,
how can I add +1 id for each enemy created?
in the past I used the enemy vision link to calculate the enemies on the field and add the value.
Now I no longer need enemy vision and would like to add the value for each enemy created subsequently.
this is what I used previously

At the beginning of the scene - change scene variable MaxEnemy ID =1

You could set the id to the number of nemici on the scene - something like InstancesInSceneCount(nemici) - (sorry, I can’t remember the exact function, and I’m away from my game dev machine).

Do this in an action straight after the enemy is created (and so in the same event).

Yes, but the expression name is actually SceneInstancesCount()

If what I’m doing is correct it doesn’t seem to work

Are you using an extension to create nemici?

yes my intention was to use this extension to spawn enemies in the game

Ah, then my suggestion may not work if multiple nemici are created at the same time.

Instead, you could to keep track of the latest id value (say a scene var named latestNemiciId). Then:

  1. create an event with the nemici just spawned an object condition
  2. then create a For each instance of nemici as a subevent, with an action to set nemici.id = latestNemiciId and a second action to add 1 to latestNemiciId.
1 Like

Hi MrMen
If this is what you suggested it doesn’t work

Not quite - both those actions should be in the same repeat event:

doesn’t seem to work the same…


I also added a text to take the variable into account but it remains at 0
textid

Maybe I’m wrong but I think the just spawned an object just tells you if the spawner just spawned an object. It picks the spawner not the spawned object.

I’ve used this in the past. It checks if the ID is the default value of zero. I believe spawners can only spawn 1 object at a time. If you have multiple spawners then you would need to use for each object.

or

there are multiple spawn points but it doesn’t seem to work

Is nemici the spawner or the spawned object. Only the spawner needs the spawn behavior. Try changing the just spawned an object to the spawner object. Everything else looks good.

It’s not this object was spawned, it’s this object spawned an object. Similar but opposite.

1 Like

you’re right Keith seems to be going now

1 Like