"pick each unit"... use that construct thing where you can define a unit variable. "Picked unit" is a big source of errors and strange behavior especially with waits. Just use a local variable and the loop where you have to set the variable. It might be called "For each unit in unit group".
Also, the design is bad because every second a thread will be created and you might not know which unit is already stutter-stepping, so you could have 2 units with the same stutter-step micro code running, so it will be order way to often.
In addition to that no more than 1 marine for each thread will stutter-step at the same time because you have a wait inside the loop.
Also, your closest enemy isn't necessarily an enemy unit, it could be an allied hover unit. But maybe all enemy units are hover units...
And your first if-condition doesn't really do anything.
A trigger that is active forms a "thread". One trigger can spawn multiple threads.
A slightly better approach for your trigger would be to:
0. Event is map initialization. Execute steps 1-5 in a never ending loop.
1. save marines in unit group
2. iterate through the unit group, find closest enemy unit, order to attack
3. wait ... game seconds
4. iterate through the unit group, find closest enemy unit, order to move
5. wait .. game seconds
Also, a loop might be better than a periodic event.
Just start the trigger at map initialization and let your code run in a loop with correct waits. This way it can't run in multiple instances and should have better performance than your first approach.
To improve it you could make the marine unit group a global variable and just add every marine that is spawned to it to avoid periodic searches for all marines.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
"pick each unit"... use that construct thing where you can define a unit variable. "Picked unit" is a big source of errors and strange behavior especially with waits. Just use a local variable and the loop where you have to set the variable. It might be called "For each unit in unit group".
Also, the design is bad because every second a thread will be created and you might not know which unit is already stutter-stepping, so you could have 2 units with the same stutter-step micro code running, so it will be order way to often.
In addition to that no more than 1 marine for each thread will stutter-step at the same time because you have a wait inside the loop.
Also, your closest enemy isn't necessarily an enemy unit, it could be an allied hover unit. But maybe all enemy units are hover units...
And your first if-condition doesn't really do anything.
A trigger that is active forms a "thread". One trigger can spawn multiple threads.
A slightly better approach for your trigger would be to:
0. Event is map initialization. Execute steps 1-5 in a never ending loop.
1. save marines in unit group
2. iterate through the unit group, find closest enemy unit, order to attack
3. wait ... game seconds
4. iterate through the unit group, find closest enemy unit, order to move
5. wait .. game seconds
Also, a loop might be better than a periodic event.
Just start the trigger at map initialization and let your code run in a loop with correct waits. This way it can't run in multiple instances and should have better performance than your first approach.
To improve it you could make the marine unit group a global variable and just add every marine that is spawned to it to avoid periodic searches for all marines.