So I as the title says I am trying to create a specific unit at 1 of 8 points that the game choses at random. The unit spawns and everything appears to run correctly along with everything else the trigger is meant to do. The problem is no matter how I set it up, I get random amounts of the unit at each point. Well I say random, but that's not entirely the case. The number spawned at each point remains the same on each test no matter how I've set it up, its just the number spawned at each is not the same.
The trigger flow I have goes basically as follows:
Variable - Set *Variable* = (Random integer between 1 and 8)
General - If then else
If
*Variable* == 1
Then
Unit - Create 1 *Unit* for Player at *Point 1*
Unit Group - Add (Last Created Unit) to *Unit Group*
Additional Trigger things
Trigger -Stop all instances of *trigger*
The If then Else repeats for all 8 points. I've tried nesting and un-nesting them. Not really sure what could be the issue at this point.
Edit: Tried using a switch to accomplish the same goal with basically the same result.
For efficiency place all points inside a point array of size 8. The first point goes in index 0 and the last point in index 7. You can then get a random point to create your unit at by getting a random integer in the range of 0 to 7 and using that as the index for the point array. This approach produces neater code (more maintainable) and runs faster.
Every time you run the code it will make a random unit at 1 of the 8 points. Due to the nature of randomness, consecutive runs might spawn units at the same point multiple times in a row. The number of units spawned in total will be equal to the number of times the code is run.
Be aware that for map testing purposes a fixed seed is often used. This means the same input will produce the same random results across multiple tests. This does not occur when played in the Arcade as then the random seed is not constant and will vary between sessions.
Well this trigger is meant to run exactly once and only once. The event that triggers this trigger is when a unit, of which there is one of on the map and no more of the unit are ever created, reaches a specific veterancy level.
Edit: By moving the setting of the variable into its own trigger, I consistently get the unit to spawn in only 1 location, however, the trigger spawns 10 units at the chosen location instead of the specified 1.
Try turning the trigger off after it first runs. Otherwise prevent it running many times by using a boolean variable. Check if boolean is false in conditions and at end of actions set it to true.
Actually I figured out it was something else. Because there is a trigger to respawn units that have been killed on the map, the trigger to respawn this unit was being run as well. The SC2 editor will run triggers for units that die, even if the event specifies a specific unit, or unit from a unit group. If you don't put in a condition as well specifying the unit again, the trigger will run anyway.
Sounds like you were not using a specific unit in the event. If the argument evaluates to null at the time the event attachment native is called (map initialization) then it will be functionally equivalent to "any unit".
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
So I as the title says I am trying to create a specific unit at 1 of 8 points that the game choses at random. The unit spawns and everything appears to run correctly along with everything else the trigger is meant to do. The problem is no matter how I set it up, I get random amounts of the unit at each point. Well I say random, but that's not entirely the case. The number spawned at each point remains the same on each test no matter how I've set it up, its just the number spawned at each is not the same.
The trigger flow I have goes basically as follows:
Variable - Set *Variable* = (Random integer between 1 and 8)
General - If then else
If
*Variable* == 1
Then
Unit - Create 1 *Unit* for Player at *Point 1*
Unit Group - Add (Last Created Unit) to *Unit Group*
Additional Trigger things
Trigger -Stop all instances of *trigger*
The If then Else repeats for all 8 points. I've tried nesting and un-nesting them. Not really sure what could be the issue at this point.
Edit: Tried using a switch to accomplish the same goal with basically the same result.
For efficiency place all points inside a point array of size 8. The first point goes in index 0 and the last point in index 7. You can then get a random point to create your unit at by getting a random integer in the range of 0 to 7 and using that as the index for the point array. This approach produces neater code (more maintainable) and runs faster.
Every time you run the code it will make a random unit at 1 of the 8 points. Due to the nature of randomness, consecutive runs might spawn units at the same point multiple times in a row. The number of units spawned in total will be equal to the number of times the code is run.
Be aware that for map testing purposes a fixed seed is often used. This means the same input will produce the same random results across multiple tests. This does not occur when played in the Arcade as then the random seed is not constant and will vary between sessions.
Well this trigger is meant to run exactly once and only once. The event that triggers this trigger is when a unit, of which there is one of on the map and no more of the unit are ever created, reaches a specific veterancy level.
Edit: By moving the setting of the variable into its own trigger, I consistently get the unit to spawn in only 1 location, however, the trigger spawns 10 units at the chosen location instead of the specified 1.
Try turning the trigger off after it first runs. Otherwise prevent it running many times by using a boolean variable. Check if boolean is false in conditions and at end of actions set it to true.
Putting a Boolean condition on it seems to have worked. No idea why it was looping to run 10 times without the condition.
Probably the event was firing multiple times.
Actually I figured out it was something else. Because there is a trigger to respawn units that have been killed on the map, the trigger to respawn this unit was being run as well. The SC2 editor will run triggers for units that die, even if the event specifies a specific unit, or unit from a unit group. If you don't put in a condition as well specifying the unit again, the trigger will run anyway.
Sounds like you were not using a specific unit in the event. If the argument evaluates to null at the time the event attachment native is called (map initialization) then it will be functionally equivalent to "any unit".