HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to simplify this trigger?

01-29-2005, 11:03 AM#1
QuakeII_best
I just need an easy way to consolidate this multiple actions triggers into one.

I use WEU.

The situation is simple... I got 12 regions (Tower 1, Tower 2...) and 12 players, and I need to create x amount of units (one tower) on each region for the corresponding player. How can I do it using a loop?

I know I can make a region array variable and assign the rects to it... but when I want to do it I fall under the same "problem" that I must set each region manually.

Is there a way to do it?

Code:
    Events
        Map initialization
    Conditions
    Actions
        -------- Towers --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[1] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 1 (Red) at (Center of Tower 01 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[2] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 2 (Blue) at (Center of Tower 02 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[3] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 3 (Teal) at (Center of Tower 03 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[4] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 4 (Purple) at (Center of Tower 04 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[5] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 5 (Yellow) at (Center of Tower 05 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[6] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 6 (Orange) at (Center of Tower 06 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[7] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 7 (Green) at (Center of Tower 07 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[8] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 6 (Orange) at (Center of Tower 08 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[9] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 9 (Gray) at (Center of Tower 09 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[10] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 10 (Light Blue) at (Center of Tower 10 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[11] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 11 (Dark Green) at (Center of Tower 11 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                PlayersInGame[12] Equal to True
            Then - Actions
                Unit - Create 1 Barracks (Mad) for Player 12 (Brown) at (Center of Tower 12 <gen>) facing Default building facing (270.0) degrees
            Else - Actions
01-29-2005, 11:38 AM#2
D0nk1ckh0t
Yes you will have to set each region manually for that array but it will be more efficient in terms of memory usage (instead of those IF-THEN you will have a single loop).
Btw creating something at a point without creating a handle var for the point and removing the point will leak memory (see memory leak prevention tutorial [here] for info).
01-29-2005, 01:46 PM#3
imwithsstupids
yeah what D0nk1ckh0t said its allot easyer to do a loop.

For each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
PlayersInGame[Integer A] Equal to True
Then - Actions
Unit - Create 1 Barracks (Mad) for Player[integer 1] at (Center of Tower[integer]<gen>) facing Default building facing (270.0) degrees
Else - Actions

thats about it but you would have to change the regions. Make another trigger that runs before that that sets tower2 (region) equal to tower[2] (variable) and so on
01-29-2005, 04:03 PM#4
QuakeII_best
Quote:
Originally Posted by imwithsstupids
thats about it but you would have to change the regions. Make another trigger that runs before that that sets tower2 (region) equal to tower[2] (variable) and so on

Thanks...

I'm a bit worried about memory leaks now :/

- So you are telling me that if I use this action I get memory leaks:

Unit - Create 1 Barracks (Mad) for Player 1 (Red) at (Center of Tower 01 <gen>) facing Default building facing (270.0) degrees


- But if I use this I won't get a leak:

Set Tower[1] = Tower 01 <gen>
Unit - Create 1 Barracks (Mad) for Player 1 (Red) at (Tower[1]) facing Default building facing (270.0) degrees

Does it matter if the rectangle (Tower 01 <gen>) is built-in into the map and not created by triggers?.

Note: I already made my variables and condensed the trigger... I'm just wondering about the memory leak issue
01-29-2005, 04:18 PM#5
imwithsstupids
Quote:
Originally Posted by QuakeII_best
Thanks...

I'm a bit worried about memory leaks now :/



i don't really know much about memory leaks. If this is a one time trigger couln't you destroy it when it is done. And destroy the region variable so it wouldn't bother you. Dont take my word on it.
01-29-2005, 04:18 PM#6
xGT4x
The problem is the (Center of (Something)), it creates a point at the center which isn't destroyed, solution: make a variable with the name "locloc" for example, then change trigger from this to the thing under it:
Old one:
Code:
Unit - Create 1 Barracks (Mad) for Player 1 (Red) at (Center of Tower[01]) facing Default building facing (270.0) degrees
New one:
Code:
Set LocLoc = (Center of Tower[01])
Unit - Create 1 Barracks (Mad) for Player 1 (Red) at locloc facing Default building facing (270.0) degrees
Custom Text: call removelocation(udg_locloc)
And at the start of the trigger, add this line(It MUST be the first action in the trigger to work):
Code:
Custom Text: local location udg_locloc
01-29-2005, 05:05 PM#7
QuakeII_best
Sweet I think I got it...

Look at this trigger... (using WEU)

Code:
All buildings
    Events
        Map initialization
    Conditions
    Actions
        -------- Shops --------
        For each (Integer A) from 1 to 8, do (Actions)
            Loop - Actions
                Set RectTempPoint = (Center of RectShopBase[(Integer A)])
                Unit - Create 1 Aura Shop for Neutral Passive at RectTempPoint facing Default building facing (270.0) degrees
                Point - Remove RectTempPoint
        For each (Integer A) from 1 to 2, do (Actions)
            Loop - Actions
                Set RectTempPoint = (Center of RectShopWENSC[(Integer A)])
                Unit - Create 1 Armor and Artifacts for Neutral Passive at RectTempPoint facing Default building facing (270.0) degrees
                Point - Remove RectTempPoint
        For each (Integer A) from 3 to 4, do (Actions)
            Loop - Actions
                Set RectTempPoint = (Center of RectShopWENSC[(Integer A)])
                Unit - Create 1 Armor and Artifacts for Neutral Passive at RectTempPoint facing Default building facing (270.0) degrees
                Point - Remove RectTempPoint
        Set RectTempPoint = (Center of RectShopBase[5])
        Unit - Create 1 Mercenaries, Mana and Life for Neutral Passive at RectTempPoint facing Default building facing (270.0) degrees
        Point - Remove RectTempPoint
Question: am I exaggerating with the Remove RectTempPoint or am I doing it just right?
01-30-2005, 09:24 AM#8
Anitarf
You're doing it right. There is not much need for removal of memory leaks when your trigger only leaks 12 point handles, but it's a good practice to do so anyway.

Also, the line "Custom Text: local location udg_locloc" is only neccesary if you have wait commands in your trigger. Without them, other triggers can't run while your trigger runs, so there's no danger of them overwriting your point variable, so it can be global, no need to make it local.
01-30-2005, 01:04 PM#9
QuakeII_best
Quote:
Originally Posted by Anitarf
You're doing it right. There is not much need for removal of memory leaks when your trigger only leaks 12 point handles, but it's a good practice to do so anyway.

Also, the line "Custom Text: local location udg_locloc" is only neccesary if you have wait commands in your trigger. Without them, other triggers can't run while your trigger runs, so there's no danger of them overwriting your point variable, so it can be global, no need to make it local.

I learnt something new :D

I know I don't have to worry about this particular trigger but (like you said) it is good practice and I have several periodic events that I need to modify to prevent leaking.

Question:

are these two the same thing (except for the variable name)?
Custom Text: call removelocation(udg_locloc)
Point - Remove RectTempPoint


I *DO* understand the difference between a global and a local variable (that's about all I know about programming).

Anyways, for the WEU GUI...
- aren't all variable global variables (by definition)?
- does your last comment affects me in anyway?, or was it directed to xGT4x?