I’m trying to make some code that spawns enemies at particular spawn points. Each enemy has a cost and when an enemy is spawned, a global variable goes down to match the enemy cost. I’ve done it this way so I can scale difficulty easily.
For some reason though, the game will not spawn multiple of one type of enemy, which is a huge problem that I don’t know how to fix.
I’ve tried a couple different things but nothing seems to work.
It’s the trigger once that’s preventing more that one spawn from happening. Have a good think about what “Trigger Once” means - if the outcomes of the conditions don’t change from the previous time it was tested, then don’t run the actions. For example, in this event:
if, for arguments sake, Enemy_Cost is 100, then it is decreased by 1 to 99. Since both conditions are still valid and evaluate the same as the previous time the conditions were evaluated, the trigger once kicks in and prevents the actions from being processed.
Only use a trigger once if you do not want an event to be actioned if the conditions are the same as the previous time. Don’t use a trigger once if the actions change the results of the conditions.
It’s not wrong as the global variable isn’t about spawning the enemy, but making sure the enemy can spawn. I’m just messing around atm and my results so far have been relatively good so I’ll test it out some more
All those events have no real actions. There’s no creation of enemy objects, there’s no reduction of enemy cost.
My recommendation, to make the whole thing more flexible an be able to increase the number of enemies, would be to do the following:
Create an object group named EnemyGroup, and add all the enemy obejcts into it (Marrikoo, Dolphn, Thor_deer, War_Boar etc)
Create a structure variable to hold the enemy details. Make it global if you are spawning enemies in a number of scenes, or make it a scene variable if you’re only spawning enemies in one scene. The structure should look like the following, and to add new enemies just add them to the structure - no need to add a new set of events: