Staredit Network > Forums > SC1 UMS Theory and Ideas > Topic: Looping through all of a unit.
Looping through all of a unit.
Mar 16 2009, 2:18 am
By: Scienthsine  

Mar 16 2009, 2:18 am Scienthsine Post #1



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.

Mar 16 2009, 2:29 am Kaias Post #2



Quote from Scienthsine
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.

Quote from Scienthsine
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.

Mar 16 2009, 2:42 am Scienthsine Post #3



Well... that would work just fine! :P

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.

Mar 16 2009, 3:07 am Moose Post #4

We live in a society.

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.




Mar 16 2009, 6:10 pm Wormer Post #5



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
Quote from Kaias
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:
Quote

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.

Mar 16 2009, 11:49 pm Scienthsine Post #6



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.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:08 pm]
Oh_Man -- example of wat u mean?
[05:59 am]
NudeRaider -- *is
[05:17 am]
NudeRaider -- despite all its flaws the sound design its fantastic
[10:29 pm]
Oh_Man -- homeworld 3 = massive disappointment
[2024-5-14. : 10:05 am]
Moose -- ya
[2024-5-14. : 5:23 am]
zsnakezz -- yes
[2024-5-12. : 8:51 pm]
l)ark_ssj9kevin -- Are you excited for Homeworld 3?
[2024-5-12. : 8:44 pm]
l)ark_ssj9kevin -- Hi Brusilov
[2024-5-12. : 4:35 pm]
O)FaRTy1billion[MM] -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
my server that was hosting it died
[2024-5-10. : 8:46 pm]
NudeRaider -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
https://armoha.github.io/eud-book/
Please log in to shout.


Members Online: 3emmae8523tM0, Ultraviolet, 3harperc672wa9