• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Trigger Omptimize

Status
Not open for further replies.
Level 17
Joined
Mar 21, 2011
Messages
1,611
hi guys. i made a trigger in my map: i want to do an out of combat system for each unit on the map (if theres no enemy in range the unit regenerates). i also used bribes unit indexer for that.
well now theres the problem that my map isn a rpg and there are lots of units on the map, cause of that it laggs a bit.
can you help me make this trigger more efficient so that it doesnt lag?


  • Combat
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set Combat_Unit = (Picked unit)
          • Set Combat_Integer = (Custom value of Combat_Unit)
          • Set Combat_Point[Combat_Integer] = (Position of Combat_Unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Conditions
              • (Number of units in (Units within 550.00 of Combat_Point[Combat_Integer] matching ((((Matching unit) belongs to an enemy of (Owner of Combat_Unit)) equal to True) and (((Matching unit) is alive) equal to True)))) greater than 0
            • 'THEN'-Actions
              • Set Combat[Combat_Integer] = True
            • 'ELSE'-Actions
              • Set Combat[Combat_Integer] = False
          • Custom script: call RemoveLocation (udg_Combat_Point[udg_Combat_Integer])
 
Level 9
Joined
Dec 12, 2007
Messages
489
store the
  • (Units in (Playable map area))
and
  • (Units within 550.00 of Combat_Point[Combat_Integer] matching ((((Matching unit) belongs to an enemy of (Owner of Combat_Unit)) equal to True) and (((Matching unit) is alive) equal to True))))
into a unit group variable, and don't forget to destroy the group afterward.
currently this trigger leaks 2 unit group every 0.5 second.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Aside from that, why does that point variable have an array?
You could just pick all units in the group and set a regular (non-arrayed) variable to the location of that unit (and then still destroy it of course).

Always use regular variables unless you really need arrays.
Like when you need 3 locations, use 3 separate variables, not 1 arrayed variable. If you do this in multiple triggers, I suggest you change that.

Correct:
  • Set tempLoc1 = (Position of (Triggering Unit))
  • Set tempLoc2 = (Position of (Target unit of ability being cast))
  • -------- Actions --------
  • Custom script: call RemoveLocation( udg_tempLoc1 )
  • Custom script: call RemoveLocation( udg_tempLoc2 )
NOT correct:
  • Set tempLoc[1] = (Position of (Triggering Unit))
  • Set tempLoc[2] = (Position of (Target unit of ability being cast))
  • -------- Actions --------
  • Custom script: call RemoveLocation( udg_tempLoc[1] )
  • Custom script: call RemoveLocation( udg_tempLoc[2] )
Yes, in your case you use a ForGroup (same as a loop basically), but the location is still temporary. So a non-arrayed variable would be just as good.
 
Status
Not open for further replies.
Top