1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Short Tutorial: Avoiding "leaks" and making efficient triggers

Discussion in 'Map Making' started by Woodenplank, Aug 25, 2015.

  1. Woodenplank
    Offline

    Woodenplank Brigand Map Maker

    Messages:
    810
    Trophy Points:
    72
    This is a short tutorial which covers the most basic "leaks" you might make when triggering.

    A leak is essentially a piece of useless memory. Imagine that you were making a triggered spell which spawned a "dummy" unit on a target point, and had the dummy cast War Stomp.
    The trigger would look like
    TriggerPic1.PNG

    This ability would work alright, but it creates several leaks. When the ability has been used there is still untapped memory, which will clutter your map and make it slower, and slower, and slower.
    First of all, the dummy unit will stand around on the map forever after having used its warstomp. It needs to be removed. For this purpose we use an expiration timer (like the one from summoned units), usually 1 second or less will suffice.
    Secondly, the unit is created at "Target Point of ability being cast" meaning that the world editor creates a point, places a unit there, and then the point remains in the memory. It is unnamed, and cannot be called or "found", but it is still filling up the map. The point must be saved in a variable, and then destroyed after the unit is spawned.
    Use this icon TriggerPic2.PNG in the trigger editor to open the variable editor. Click New Variable, and a window will pop up.
    TriggerPic3.PNG
    The new variable can be called whatever you like (though you cannot use spaces, use underscores _ instead)
    There are several variable types such as unit, point, unit group, special effect, timer, and so on. Right now we need a point.

    Array and Initial Value will not be necessary for this tutorial.

    A leak-free trigger will look like
    TriggerPic4.PNG
    Note the custom script at the end. This is what destroys the Point variable (destroys as in: empties the memory).
    When doing custom scripts take note of where spaces and capitalizations are, "remove location" does not work, but "RemoveLocation" does. The "udg_" in front of the variable name is also important.
    (Sorry about mispelling "temporary" here, but actually as long as the custom script and variable name matches, it makes no difference)

    You might also create a leak when selecting units. Let's say you wanted to select units around the target point, and deal some damage to them, without a dummy.
    Again you must first set a Unit Group variable, and then destroy it afterwards. Or use the second method, seen below.
    TriggerPic5.png
    Note how we also manage the point variable here, and avoid a leak when creating the group.
    The third picture, the one with "also good" is another way. When putting the custom script "set bj_wantDestroyGroup = true" right before a group action, the leak will automatically be removed IMMEDIATELY after the group action. Both scripts can be used, but if you wish make multiple references to a group, you'll want to save it in a variable, and remove it later.

    NOTE: As a rule of thumb, it is a good idea to declare units in variables. For the trigger with the dummy unit, it would be a good idea to set "Temporary_unit = last created unit", and in the following actions replace (Last Created Unit) with "Temporary_unit" instead. I'm not a programmer or nothing, so I can't explain why, but it does help efficiency.
    Think of it as the difference between "calculate 2+2, calculate 2+2, calculate again..." and "set Name=2+2, reference Name, reference Name..." the processor doesn't make the calculation over and over again.

    EDIT:
    On the advice of Krystalknoct I have updated the tutorial to include the scripts and/or GUI actions for dealing with other common leaks. I'll make a short list, as I have already explained what leaks are and all...
    As I have already covered locations and group variables, let us proceed with the rest...

    1. Floating Text
    Floating text is... floating text. A line of text/numbers that appears at a location or over a unit. Note that when placing floating text at a point, rather than above a unit, you will have to deal with a point variable as well.
    There are two ways to deal with floating text, the latter being the most useful in my opinion:
    Trigger1.PNG
    Trigger2.png
    Changing the lifespan of a floating text will work much like an expiration timer for units - but you need to disabled permance first, else nothing happens.

    2. Player Groups
    Player groups are much like unit groups; they have no real in-game effect, but is the editor's way of handling multiple players and for looping through these.
    In the trigger below, all players who are playing (meaning no closed slots) have the "Animate Dead" ability disabled for them. The player group variable is then removed.
    Trigger3.png

    3. Special Effects
    Admittedly, this should have been in here to begin with. Special effects are some of the most used things in custom triggered spells, and cleaning the leaks is very important.
    Special effects are... special effects. Things like the thunderclap crackle, the flamestrike explosion, Holy Light's... light.
    NOTE: Like floating text, Special effects can be attached to units or simply created at set points. Be mindful of the difference, as the latter requires a point variable and leak cleaning.

    Dealing with special effects in GUI is easy:
    Trigger4.png
    This displays a Thunderclap special effect at the center of the map at map start. Then removes leaks. Simple enough, right?
    NOTE: While special effects will mostly get to display before they are destroyed, it is not always so! Sometimes they're destroyed so fast, that nothing is seen. In this case, it is actually better to use a dummy unit - having the model changed to the appropriate effect.
    Truly, using dummy units instead of effects (and then adding a short expiration timer) is actually easier on the processor than using special effects, but this requires making a dummy for every effect you wish to use.
    Trigger5.png
    Just remember to make the dummy untargetable, invulnerable, and without a shadow.

    4. Sound
    Like special effects, sounds can mostly be destroyed right after playing, and people will still get to hear them.
    TriggerShort1.PNG

    5. Lightning
    Like with floating text, you would probably want to save your "last created lightning effect" in an appropriate variable, and destroy it after a while.
    TriggerShort2.png

    And finally; everything else. Remember to remove stuff like items, created weather effects, units, destructibles, and so on. There are simply GUI actions for all - as a rule of thumb, if there's a "Destroy XXX" or "Remove YYY" action, you want to use that.
    • Like Like x 3
    • This This x 2
    • Winner Winner x 1
    • Informative Informative x 1
    Last edited: Dec 3, 2017
  2. EmperorFawful
    Offline

    EmperorFawful Gatsby Guardian Website Admin

    Messages:
    3,808
    Trophy Points:
    138
    Is the custom script applyable to any variable I theoretically create?
    Actually wonder, as I'm always uncertain upon those, when doing work on AW:DoT, as AW also works with them.
  3. Woodenplank
    Offline

    Woodenplank Brigand Map Maker

    Messages:
    810
    Trophy Points:
    72
    I couldn't tell you if there was a custom script for all variables, but I reckon there ought to be. But "DestroyGroup" or "RemoveLocation" are specific to unit groups and locations, if you wanted to destroy a player group, the you can't simply write "DestroyGroup" or "RemovePlayerGroup" - whatevever. It has to be the proper, specific custom script. I.e. "DestroyForce".
    Though if you just have something like a unit variable, if the unit dies that'll be enough.

    I just covered the most basic leaks, the ones which will appear most often in triggers I find.

    EDIT: More leaks and appropiate custom scripts added. Note that many objects can be removed with GUI code, for instance; special effects, lightning effects, and sounds can be removed with simple GUI actions.
    • Informative Informative x 1
    Last edited: Oct 25, 2015
  4. crystalknoct
    Offline

    crystalknoct

    Messages:
    20
    Trophy Points:
    3
    I dont mean to be rude but it would probably be nice for the people here if yo add this informaton to your post aswell there as many other things you missed that leak.
    http://www.hiveworkshop.com/forums/general-mapping-tutorials-278/complete-list-things-leak-126761/
    http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/memory-leaks-263410/
  5. BuzanandFriends
    Offline

    BuzanandFriends The Mighty All-father. Brigand

    Messages:
    401
    Trophy Points:
    60
    i love you're Halloween costume, so appropriate and not semi-demeaning to this forum at all...-rubs eyes- IF YOU GUYS NEED ME! AND YOU PROBABLY WONT! BUT I'LL BE OFF DRINKING BURBAN! GRANPAPPY BUZAN SEEN TO MUCH SHIT
  6. SvnmS
    Offline

    SvnmS Brigand Map Maker

    Messages:
    1,383
    Trophy Points:
    135
    I don't think "Target unit of ability being cast" leaks even if used directly.
    AFAIK only when you use something like "position (unit)" will the leak happen, because in that case, the game actually creates a new object, in the case of "Target unit of ability being cast" it doesn't.
  7. crystalknoct
    Offline

    crystalknoct

    Messages:
    20
    Trophy Points:
    3
    I believe the above person is correct.
  8. Uther01
    Offline

    Uther01 God of champions Brigand Map Maker

    Messages:
    3,354
    Trophy Points:
    130
    Im still not a that great fan of the dummy system, since there is nearly for every ability you want to create a Preset, like the thing you teached me for Mass Bloodlust and btw. Do you know the other Version of the Mass BL. Because it is considered as a negative ability and spell immun units arent affected by it.
  9. Woodenplank
    Offline

    Woodenplank Brigand Map Maker

    Messages:
    810
    Trophy Points:
    72
    I don't believe I said it did? I'm confused....
    Any way, no. "Target unit of ability being cast" doesn't leak. "Target point" or "position of target unit" do, however, leak position objects.

    If I'm getting this right, you want a Mass Bloodlust spell that wasn't, like I explained in the thread, based off on "Silence"? But you don't want to use dummies either? Because in that case I'm stumped.
    Any way, the dummy version of the spell should affect spell immune targets, and be considered positive. Just make a unit group of all the targets (friendly, live units within AoE-range of the target point) and loop through them, creating a dummy and having it cast Bloodlust for each one.
    - If you do like described above, be mindful of leaks! You have to add an expiration to each dummy, and you will also have a position for every dummy you create (depending on a few tweaks in the trigger), and you will always need one for the target point.
  10. SvnmS
    Offline

    SvnmS Brigand Map Maker

    Messages:
    1,383
    Trophy Points:
    135
    I think this says it causes leaks, unless you meant something different.