well a unit group array is sort of interesting because it turns the units into an array, and picking a particular unit from a unit group that is made into an array is like referencing an array within an array. (confusing right?)
So to separate lets say we have one element of your array called unit group variable[5], and lets also say previously you added a marine, then a marauder, then a ghost to that unit group. within that unit group array the marine is saved as unit 1, the marauder as unit 2, and the ghost as unit 3. So each unit that is added to the unit group is given a particular number within that unit group, and think of the number within the brackets represents a completely different group of units.
So you have to keep track of which units were added in what order if you want to reference a particular unit within a unit group. In order to grab this particular unit within a unit group, you must use the "unit from unit group (#)" command located within a trigger itself (an example of this below), and the (#) representing the array of units within that unit group.
I guess if you wanted to have multiple unit types, you could simply pick each unit within unit group of a certain unit type and then do whatever you please with them, that may be an easier more manageable way if you want to not keep track of what units come in and out at what times. I also do not believe that you can directly modify say marine(1) and marine(5) to switch places in the unit group array. If you are wanting to reference specific units many times for your purposes, I would stick with a unit variable and set that to an array and have that as your "unit group".
Hope that helps!
example (bold represents clickable):
order (unit 1 from unit group variable[5] to (Burrow ) ( replace existing orders )
What exactly are you trying to do? If you plan to have a bounded number of units in the unit group with particular places then maybe consider a 2D unit array instead. Groups are meant to be used as sets of units where internal placement inside the group is unimportant so what you are trying to do is sort of outside their use case. By elaborating what you intend to do and why there might be alternative solutions that are easier/more efficient that you are unaware of (triggering can be complex stuff at times).
It may be possible to order units inside a group by clearing it and adding them in the correct order. More efficient would be to swap the group so you pull units from one in the correct order and put them straight into a new unit group which you eventually use to replace the first. That is if units are given a place inside the group based on order of addition and not some internal data structure mechanic based on some internal identifier. For example if a group was a AVL tree of units then the ordering might be based on internal numbers outside your control.
Arrays are typically most used in multiplayer games to account for players. Since players are identified as merely integers, you can have a single array store something like units specific to the index that matches the player integer. Also very helpfully for groups of attached dialogs items since you can just use a loop to loop though numbers which nicely coincides with the index of the array.
If your using a unit group array then your using it to store many units specific to something else. Otherwise if you just want to store a single unit in an index use a regular unit array.
@ImperialGood: Go
oh yea i guess i meant how to add units to a "2D unit array" like you say
just a unit array, not a unit group array which would be an array inside an array.
To answer your question in short
i have two teams.
one spawns top of map as terran. second team spawns bottom as protoss.
its a micro game in which team must kill enemy nexus to win.
each player starts with one civilian. terran civilians on the left with terran selection of units . for example (choose between 12 marines or 5 hellions, etc.)
protoss team on the right.
when civilian chooses the unit selection, it dies. and army units spawn by nexus. when all army dies, then civilian respawns again for another selection.
Also : more kills= more minerals. every 300 minerals benchmark you get an extra civilian during selection.
I had like 30 separate triggers to achieve all this and it works, but i think it caused problems with team setup and also slowed down the map heavily. I was told it could be done in one trigger with a unit array
Sounds like a simple unit group per player would suffice. When any unit dies you check the group for the owner (use his player as the index in the group array) and if the number of living units in the group is 0 (everything dead) then respawn X civilians (where X is stored in an integer array representing how many civilian milestones he reached).
If you mean that the civilians respawn once all the units it created die (not when all units the player owns are dead) then it is more tricky. In that situation I would recommend using threads for holding the group of spawned units in a local group and then periodicly polling it (every 5-10 seconds) to check if all units in it are dead or not. This would handle the dynamic memory nature of the problem although it does add a upper bound to the number of civilians that can exist (something you should have anyway to prevent poor performance).
when i say civilians respawn once all the units it created dies, it also means when all the units the player owns are dead. same thing, since all the units the player owns at the moment has been created from civilian. basically I have the civilians take up 1 supply and every army unit takes up 10 supply each. that way i can have a condition to check to see if the players supply is under 10,that means the whole army must have died. thats the system i have right now that supports up to 9 civilian count (more than enough imo)
btw how would I go about making a unit group per player? i know how to make a unit group but my original question remains unanswered : how do i add units to a unit group and how do i know which integer stands for which unit?
Add it to the player group at the index of the civilian owner player. Players are integers in SC2 so you can use them directly as array indices. The position in the group is unimportant as you only want to use it for its set like properties.
Quote:
how do i know which integer stands for which unit?
Does not mater as you are using it as a set to determine when all units are dead. If the set is empty of living units then everything is dead and respawn the civilians. You keep track of the number of civilians to respawn for each player in an integer array.
Quote:
btw how would I go about making a unit group per player?
Global variable, set to type group and enable the array flag. Set size to 16. Only use players as indices for the array.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
EDIT: what i really mean it how to create a Unit array and set up the integers for each unit?
i have searched all over the forum and surprisingly am not finding the answer to this problem. maybe its more basic than i thought?
I know how to make a variable and then choose from the dropdown menu "unit group" and choose array, and then make the number as high as i want to.
but how do i set it so that a certain unit = a certain integer? for example if i have a Unit Group A
and i want SCV = 1 from Unit Group A.... Probe = 2 from Unit Group A..... marine = 3 from Unit Group A .....
etc..
do i have to set it up as an action in a trigger? do i do it elsewhere?
@eocwoof: Go
well a unit group array is sort of interesting because it turns the units into an array, and picking a particular unit from a unit group that is made into an array is like referencing an array within an array. (confusing right?)
So to separate lets say we have one element of your array called unit group variable[5], and lets also say previously you added a marine, then a marauder, then a ghost to that unit group. within that unit group array the marine is saved as unit 1, the marauder as unit 2, and the ghost as unit 3. So each unit that is added to the unit group is given a particular number within that unit group, and think of the number within the brackets represents a completely different group of units.
So you have to keep track of which units were added in what order if you want to reference a particular unit within a unit group. In order to grab this particular unit within a unit group, you must use the "unit from unit group (#)" command located within a trigger itself (an example of this below), and the (#) representing the array of units within that unit group.
I guess if you wanted to have multiple unit types, you could simply pick each unit within unit group of a certain unit type and then do whatever you please with them, that may be an easier more manageable way if you want to not keep track of what units come in and out at what times. I also do not believe that you can directly modify say marine(1) and marine(5) to switch places in the unit group array. If you are wanting to reference specific units many times for your purposes, I would stick with a unit variable and set that to an array and have that as your "unit group".
Hope that helps!
order (unit 1 from unit group variable[5] to ( Burrow ) ( replace existing orders )
What exactly are you trying to do? If you plan to have a bounded number of units in the unit group with particular places then maybe consider a 2D unit array instead. Groups are meant to be used as sets of units where internal placement inside the group is unimportant so what you are trying to do is sort of outside their use case. By elaborating what you intend to do and why there might be alternative solutions that are easier/more efficient that you are unaware of (triggering can be complex stuff at times).
It may be possible to order units inside a group by clearing it and adding them in the correct order. More efficient would be to swap the group so you pull units from one in the correct order and put them straight into a new unit group which you eventually use to replace the first. That is if units are given a place inside the group based on order of addition and not some internal data structure mechanic based on some internal identifier. For example if a group was a AVL tree of units then the ordering might be based on internal numbers outside your control.
@eocwoof: Go
Arrays are typically most used in multiplayer games to account for players. Since players are identified as merely integers, you can have a single array store something like units specific to the index that matches the player integer. Also very helpfully for groups of attached dialogs items since you can just use a loop to loop though numbers which nicely coincides with the index of the array.
If your using a unit group array then your using it to store many units specific to something else. Otherwise if you just want to store a single unit in an index use a regular unit array.
@ImperialGood: Go oh yea i guess i meant how to add units to a "2D unit array" like you say just a unit array, not a unit group array which would be an array inside an array.
To answer your question in short
i have two teams. one spawns top of map as terran. second team spawns bottom as protoss. its a micro game in which team must kill enemy nexus to win.
each player starts with one civilian. terran civilians on the left with terran selection of units . for example (choose between 12 marines or 5 hellions, etc.) protoss team on the right.
when civilian chooses the unit selection, it dies. and army units spawn by nexus. when all army dies, then civilian respawns again for another selection.
Also : more kills= more minerals. every 300 minerals benchmark you get an extra civilian during selection.
I had like 30 separate triggers to achieve all this and it works, but i think it caused problems with team setup and also slowed down the map heavily. I was told it could be done in one trigger with a unit array
Sounds like a simple unit group per player would suffice. When any unit dies you check the group for the owner (use his player as the index in the group array) and if the number of living units in the group is 0 (everything dead) then respawn X civilians (where X is stored in an integer array representing how many civilian milestones he reached).
If you mean that the civilians respawn once all the units it created die (not when all units the player owns are dead) then it is more tricky. In that situation I would recommend using threads for holding the group of spawned units in a local group and then periodicly polling it (every 5-10 seconds) to check if all units in it are dead or not. This would handle the dynamic memory nature of the problem although it does add a upper bound to the number of civilians that can exist (something you should have anyway to prevent poor performance).
@ImperialGood: Go
when i say civilians respawn once all the units it created dies, it also means when all the units the player owns are dead. same thing, since all the units the player owns at the moment has been created from civilian. basically I have the civilians take up 1 supply and every army unit takes up 10 supply each. that way i can have a condition to check to see if the players supply is under 10,that means the whole army must have died. thats the system i have right now that supports up to 9 civilian count (more than enough imo)
btw how would I go about making a unit group per player? i know how to make a unit group but my original question remains unanswered : how do i add units to a unit group and how do i know which integer stands for which unit?
Add it to the player group at the index of the civilian owner player. Players are integers in SC2 so you can use them directly as array indices. The position in the group is unimportant as you only want to use it for its set like properties.
Does not mater as you are using it as a set to determine when all units are dead. If the set is empty of living units then everything is dead and respawn the civilians. You keep track of the number of civilians to respawn for each player in an integer array.
Global variable, set to type group and enable the array flag. Set size to 16. Only use players as indices for the array.