I'm trying to think up a way of looping through all of a type of unit, and doing something at each of their locations. All of the triggers that affect a unit always seem to target the left-most-top unit of the type, owner and location. I was thinking about using MoveLocation to select a unit, then do whatever, then give that unit to player 9/10/11/12. In a sperate trigger if the player commanded no units of that type, then give all of the units from player 9/10/11/12 back to the player.
This would take trigger cycles equal to the amount of units looped through, to complete... so not perfect, also in a game with more than 6 players there aren't enough players left over to be doing this per player.
Soooo.... is there a better way? Input appreciated.
None.
All of the triggers that affect a unit always seem to target the left-most-top unit of the type, owner and location.
It acts upon the leftmost; ties are broken by the most recently acted upon unit.
This would take trigger cycles equal to the amount of units looped through, to complete... so not perfect, also in a game with more than 6 players there aren't enough players left over to be doing this per player.
You can repeat the operation within the loop rather than just once per loop.
EX: Say I want to make an explosion on top of every marine in the map for some player:
Player X brings at least 1 'Terran Marine' to 'Anywhere'
---
Move location 1 on Terran Marine for Player X
Create 1 Terran Wraith at location 1
Kill all Terran Wraith at location 1
Give 1 Terran Marine for Player X to Neutral at Anywhere
You'd repeat this trigger as many times as the maximum number of marines player X could have on the map, and then afterward:
Neutral brings at least 1 Terran Marine to Anywhere
----
Give all Terran Marine for Neutral to Player X
Simple
None.
Well... that would work just fine!
Thank you, seems trivial to me now, but maybe someone should put this up in the wiki... for teh n00bs.
Another question, does SC execute all of a players triggers, then the next players, etc, then repeat? Or is it in some other order?
None.
It executes all the triggers for each player once per cycle in order by the player's number. Player 1's triggers will run first. (he will also run each trigger for All Players and triggers owned by the force he is in) Repeat for Player 2, etc.
Look
this about triggers execution order.
Scienthsine, the method is fine until you execute too many 'Give Unit' actions per loop. The problem is 'Give Unit' is a very laggy action and you exhaust the cpu limit (map begin to lag) very soon. Dont use it if you are going to loop through units every trigger loop.
If those units you want to loop through are static (dont move) better use a location for each one or a grid.
Also if you want to easily multiply and manage triggers consider
MacroTriggers tool.
For example, on MacroTriggers the next triggers
EX: Say I want to make an explosion on top of every marine in the map for some player:
Player X brings at least 1 'Terran Marine' to 'Anywhere'
---
Move location 1 on Terran Marine for Player X
Create 1 Terran Wraith at location 1
Kill all Terran Wraith at location 1
Give 1 Terran Marine for Player X to Neutral at Anywhere
You'd repeat this trigger as many times as the maximum number of marines player X could have on the map, and then afterward:
Neutral brings at least 1 Terran Marine to Anywhere
----
Give all Terran Marine for Neutral to Player X
could be written like this:
REPEAT 100
TRIGGER
OWNERS: player
CONDITIONS:
Bring(@P(X), @AtLeast, 1, @U("Terran Marine"), @Anywhere)
ACTIONS:
MoveLocation(@L("Location 1"), @U("Terran Marine"), @P(X), @Anywhere)
CreateUnit(1, @U("Terran Wraith"), @L("Location 1"), @CurrentPlayer)
KillUnit(@All, @U("Terran Wraith"), @L("Location 1"))
GiveUnits(1, @U("Terran Marine"), @P(X), @Anywhere, @P(12))
ENDT
ENDL
TRIGGER
OWNERS: player
CONDITIONS:
Bring(@P(12), @AtLeast, 1, @U("Terran Marine"), @Anywhere)
ACTIONS:
GiveUnits(@All, @U("Terran Marine"), @P(12), @Anywhere, @P(X))
ENDT
One advantage of using this is when you want to correct a mistake (for example, insert "Preserve Trigger" action) you dont need to modify all 100 triggers.
Some.
Thanks for the info
Wormer> Good to know, I don't think it'll be a problem in my case as I won't be doing it for many units, and not very often. As for the macro thing, looks cool and definitely a useful tool for mappers... but I program quite a bit, so it's a trivial task. Takes almost no time for me to throw some regular expressions in there and run it through some repeats, replaces, macro expansion, etc.. in c or lua or something.
None.