I've been attempting to create a "stutter stepping" AI for marines. It's working well so far, the only problem is that only one marine stutter steps at any given point in time. After the marine dies, another takes its place. This is the code:
"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.
As I understand it, "Closest Enemy" is only set for one of the picked marines and therefore the others don't attack.
I tried to use the "For each unit in unit group" function, but it asks for a specific variable as well.
"For each unit [Unit Variable] in [Unit Group Variable]."
This suggests, then, that I have to apply a variable to every marine in use. Problem here is that I don't know how to do that without any integers.
Any suggestions..?
Thanks again for the help.
EDIT: I managed to fix it and it works perfectly now, thank you.
If anyone's curious, I simply moved the "Pick Each Unit" command from the start and placed it just before "Set Variable - Closest enemy". This way, all the marines are given a "closest enemy". Yes, /facepalm for the easy solution.
Hello.
I've been attempting to create a "stutter stepping" AI for marines. It's working well so far, the only problem is that only one marine stutter steps at any given point in time. After the marine dies, another takes its place. This is the code:
I realise there are perhaps more refined methods to do this, but it's only experimenting.
Does anyone have any idea what might be causing this?
"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.
@Ahli634: Go
Thanks for all the help! Seems like there's a lot of criticism on my code, heh.
I've tried to do as you say, and at least now the problem is a bit more clear.
As I understand it, "Closest Enemy" is only set for one of the picked marines and therefore the others don't attack. I tried to use the "For each unit in unit group" function, but it asks for a specific variable as well.
"For each unit [Unit Variable] in [Unit Group Variable]."
This suggests, then, that I have to apply a variable to every marine in use. Problem here is that I don't know how to do that without any integers. Any suggestions..? Thanks again for the help.
EDIT: I managed to fix it and it works perfectly now, thank you. If anyone's curious, I simply moved the "Pick Each Unit" command from the start and placed it just before "Set Variable - Closest enemy". This way, all the marines are given a "closest enemy". Yes, /facepalm for the easy solution.