[Solved] Why does this Leak?

Status
Not open for further replies.
Level 4
Joined
Sep 25, 2015
Messages
61
1708459603571.png

AFAIK item groups don't leak but testing in-game I start lagging within less than a minute
 
Last edited:
I thought it shouldn't too, but when I tested in-game it lagged like hell and didn't without the trigger
That's probably because you are looping through all the units on the map every 0.10 seconds, applying conditions, and ordering them to target an item - all of them (that match). So it would not surprise me if it lagged.
 
Oh, you're right nvm. I knew it was bad but not that bad. Theres no lag with 1s timer event
Remember, you can manually manage your Unit Groups. It's far easier for the game to process this in multiple steps spread over time:
  • Events
    • Unit - A unit Enters playable map area
  • Conditions
    • (Owner of (Triggering unit)) Equal to Player 21 (Coal)
  • Actions
    • Unit Group - Add (Triggering unit) to Player_Units[21]
^ Or better yet use an Event that's more specific to your situation -> "A unit is Trained/Summoned" or Add them after you Create them with triggers.
  • Events
    • Unit - A unit Dies
  • Conditions
    • (Owner of (Triggering unit)) Equal to Player 21 (Coal)
  • Actions
    • Unit Group - Removes (Triggering unit) from Player_Units[21]
^ We're now doing things in a way that is Event based which is great since it removes the random time element from it. You now know PRECISELY when Player 21 has run out of units which is quite useful. You could even throw in an Integer variable to track the number of these Units so you can display them in a Multiboard or whatever -> "Number of enemies remaining".

Constantly rebuilding the Unit Group over and over again is often unnecessary, inefficient, and just bad triggering practice.

Plus, you can probably narrow it down even further like Pyro suggested. I doubt that you actually need to order ALL of those Units to get the Meat. How about just certain types? Or how about just ordering X amount of them from the Unit Group where X is the number of Meat. There's always optimizations that can be made.
 
Last edited:
Status
Not open for further replies.
Back
Top