• 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] [Simple] Clarification with Leaks

Status
Not open for further replies.
Level 3
Joined
May 15, 2011
Messages
30
Greetings you helpful hivers!

There's a really fun map that I began playing recently with a friend, but one thing that I noticed that after every single game at around the hour point it became almost unplayable because (from what I've recently researched as) of leaks!

It spawns at center of location every minute, then creates an item which is like a tome (gold coins) on that units death (which happens frequently). It also creates wild animals at random point in multiple locations, and it creates a ping at center of location on command.

So after learning just today that these leaks were the most likely issue I've been trying to clean up all the leaks! First of all I put this system in the map, to deal with all the gold coins after you pick them up. But now I'm just a little confused on how to clean up the areas.

You see, some of the triggers after creating units, inside the same trigger will pick all units inside the region and give them an order, and as I've read unit groups also leak. So my question is thus:

  • Caravan Coast
    • Events
      • Time - Every 110.00 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint = Caravan Traveling spawn <gen>
      • Unit - Create 1 Caravan for Player 12 (Brown) at (Center of TempPoint) facing Default building facing degrees
      • Unit Group - Order (Units in TempPoint owned by Player 12 (Brown)) to Move To (Center of Travler End of the Road 1 <gen>)
      • Custom script: call RemoveLocation (udg_TempPoint)
Will this fix it, or do I need to make the "Units in TempPoint" a variable as well? Or perhaps there is a cleaner way to fix this in a single trigger rather than editing all the other triggers? Somehow I doubt that is possible though.

Also, I would like to know if this would leak:

  • Market Ping
    • Events
      • Player - Player 1 (Red) types a chat message containing -Market as An exact match
      • Player - Player 2 (Blue) types a chat message containing -Market as An exact match
      • Player - Player 3 (Teal) types a chat message containing -Market as An exact match
      • Player - Player 4 (Purple) types a chat message containing -Market as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -Market as An exact match
      • Player - Player 6 (Orange) types a chat message containing -Market as An exact match
      • Player - Player 7 (Green) types a chat message containing -Market as An exact match
      • Player - Player 8 (Pink) types a chat message containing -Market as An exact match
    • Conditions
    • Actions
      • Cinematic - Ping minimap for (All players) at (Center of Market 1 <gen>) for 5.00 seconds
      • Cinematic - Ping minimap for (All players) at (Center of Market 2 <gen>) for 5.00 seconds
      • Cinematic - Ping minimap for (All players) at (Center of Market 3 <gen>) for 5.00 seconds
      • Cinematic - Ping minimap for (All players) at (Center of Market 4 <gen>) for 5.00 seconds
      • Cinematic - Ping minimap for (All players) at (Center of Market 6 <gen>) for 5.00 seconds
So far I've really enjoyed fixing up all the little parts of the triggering that I do now how to fix up, but there is so much more I need to learn!

All help would be appreciated! :)
 
Level 20
Joined
Apr 14, 2012
Messages
2,901
In the first set of triggers you're already leaking.
Do this:

  • Caravan Coast
    • Events
      • Time - Every 110.00 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint[1] = (Center of Caravan Traveling spawn <gen>)
      • Set TempPoint[2] = (Center of Travler End of the Road 1 <gen>)
      • Unit - Create 1 Caravan for Player 12 (Brown) at (TempPoint) facing Default building facing degrees
      • Set Group = (Units in TempPoint owned by Player 12 (Brown)) to Move to TempPoint[2]
      • Unit Group - Pick every unit in Group and do (Actions)
    • Loop - Actions
      • Unit Group - Order Picked Unit to Move To TempPoint[2]
      • Custom script: call RemoveLocation (udg_TempPoint[1])
      • Custom script: call RemoveLocation (udg_TempPoint[2])
      • Custom script: call DestroyGroup(udg_Group)


For the second trigger store all of the (Center of Market 1/2/3/4/5/6 <gen>) into a point variable, and then use that variable to set where the minimap will be pinged.

If you want more info on leaks, read this tutorial by Ralle: Leaks
 
Level 3
Joined
May 15, 2011
Messages
30
Ah, I thought I'd missed something! :)

Also, when I'm setting the variable TempPoint (which I've now changed to an array) I don't seem to be able to set it to "Center of", rather it just sets it to "Caravan Traveling spawn" (I really need to fix up these spelling errors as well xD). How do I go about setting it to "Center of", it doesn't seem to be in Preset, Variable or function.

Also, should I make the TempPoint array a large array with a separate index for each triggering area? For example, I have another trigger which requires 5 different areas, should I make them TempPoint[3] TempPoint[4] etc. ?

Edit: I get a compile error for "call RemoveLocation (udg_TempPoint[2])". It says Line 536: Invalid argument type (rect), any ideas?
 
Last edited:
Level 20
Joined
Apr 14, 2012
Messages
2,901
One, TempPoint is set originally to (find this function) Center of Region. That Region can then be changed into either the preplaced regions (like Playable Map Area) or the other locations (like Position of unit) in this case you are going to set it to the Center of Caravan Travelling Spawn <gen>, assuming that it is a region.

Also, since you are removing the location, I guess you shouldn't need to separate the indexes for each triggering area, unless you're using those areas simultaneously.

So for example, you do this:
  • TEST
  • Events
    • A Unit starts the effect of an ability
  • Conditions
    • (ability being cast) equal to A SPELL
  • Actions
    • Set POINT[1] = (Position of (Triggering unit))
    • Item - Create Tome of Experience at POINT[1]
    • call RemoveLocation(udg_POINT[1])
And then you have another trigger:
  • Test 2
  • Event
    • A Unit Starts the effect of an ability
  • Conditions
    • (ability being cast) equal to A SPELL 2
  • Actions
    • Set Point[2] = Position of Another Unit
    • Item - Create Tome of Experience at POINT[1]
    • call RemoveLocation(udg_POINT[1])
Now these are just examples (normally you don't have to separate triggers when they are like this) to show you a point. Assuming that A SPELL is cast. It will create the item at POINT[1]. POINT[1] is then removed. Then next A SPELL 2 is cast. It creates the item at POINT[1], then removes the point. This is fine. But when done at the same time, you won't get the same result (that's why some spells are MUI)

So now, if you use the triggering areas you are saying simultaneously you might need to use other indexes for the TempPoint. Or if it's unit arrays with indexes we're talking about, then the spells section has some great unit indexers.

But of course you may also use higher indexes for other points and go from 1,2,3,4,5,6,7,8,9... and so on. But don't exceed 8191.
You may also use a variable integer that adds 1 to itself for the arrays:
  • test
    • Events
    • Conditions
    • Actions
      • Set Integer = (Integer + 1)
      • Set POINT[Integer] = (Position of Paladin 0000 <gen>)
      • Item - Create Tome of Experience at POINT[Integer]
      • Custom script: call RemoveLocation(udg_POINT[udg_Integer])
      • Set Integer = (Integer - 1)
Then just subtract 1 again when your done using it. Though this method is very simple and sometimes, unreliable. But that's just sometimes.
 
Level 3
Joined
May 15, 2011
Messages
30
I get a compile error for "call RemoveLocation (udg_TempPoint[2])". It says Line 536: Invalid argument type (rect), any ideas?
 
Level 3
Joined
May 15, 2011
Messages
30
The updated trigger is as follows:

  • Caravan Coast
    • Events
      • Time - Every 110.00 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint[1] = Caravan Traveling spawn <gen>
      • Set TempPoint[2] = Travler End of the Road 1 <gen>
      • Unit - Create 1 Caravan for Player 12 (Brown) at (Center of TempPoint[1]) facing Default building facing degrees
      • Set TempGroup[1] = (Units in TempPoint[1])
      • Unit Group - Order TempGroup[1] to Move To (Center of TempPoint[2])
      • Custom script: call DestroyGroup(udg_TempGroup[1])
      • Custom script: call RemoveLocation(udg_TempPoint[1])
      • Custom script: call RemoveLocation(udg_TempPoint[2])
 
Level 3
Joined
May 15, 2011
Messages
30
It is a region, which is why I was confused as to why there was no option to make it the center. The world editor did not give me an option for center of, it just made the variable equal the region.
 
Level 3
Joined
May 15, 2011
Messages
30
Ah! That worked perfectly! I'm just having a little trouble finding
  • Set Group = (Units in TempPoint owned by Player 12 (Brown)) to Move to TempPoint[2]
As all I see to choose from is this:

pvz3bl.jpg


and

ojryqi.jpg


There isn't a choice to pick a "point" in any of the variable dropdown boxes, so I can't make this:

  • Set Group = (Units in TempPoint owned by Player 12 (Brown))
You've been really helpful so far! Thank you so much for your patience! :)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
It looks like you want to do this:
  • Caravan Coast
    • Events
      • Time - Every 110.00 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint1 = Center of (Caravan Traveling spawn <gen>)
      • Set TempPoint2 = Center of (Travler End of the Road 1 <gen>)
      • Unit - Create 1 Caravan for Player 12 (Brown) at TempPoint1 facing Default building facing degrees
      • Set TempGroup1 = (Units in Caravan Traveling spawn <gen>)
      • Unit Group - Order TempGroup1 to Move To TempPoint2
      • Custom script: call DestroyGroup(udg_TempGroup1)
      • Custom script: call RemoveLocation(udg_TempPoint1)
      • Custom script: call RemoveLocation(udg_TempPoint2)
      • Custom script: set udg_TempGroup1 = null
      • Custom script: set udg_TempPoint1 = null
      • Custom script: set udg_TempPoint1 = null
 
Level 3
Joined
May 15, 2011
Messages
30
The project was originally called: Rome, and it was by Mageweaver01 and I suppose Dread_Dragon as well, but I don't know if Dread_Dragon is an official editor or just started editing after Mageweaver01 stopped. I've been trying to contact Mageweaver01 but to no avail (he's got an account on hive, so I'm hoping he logs in one day and responds).

You can find the map here.

As to being in the development section, I would LOVE to put it there, the only problem is I don't have an official okay to go from the original creator/s so that's against the hive rules from what I've read.

A valid author:
  • If the author's name is different from the uploader's name, please tell us if it's just another one of your usernames.
  • If you are simply uploading the map of another user to share it with people, without the author's permission, then the map will be rejected.

So maker, in doing:
  • Custom script: set udg_TempGroup[1] = null
  • Custom script: set udg_TempPoint[1] = null
  • Custom script: set udg_TempPoint[2] = null
Would that not be moot, as the variables have already been destroyed? Also, if not, what does that help me with?

I assume by destroying the variables they thereby become unusable, so should I reset them to null after each use so that they can continue to spawn at every XX second interval?

Edit: Oh, and I've decided to rename my little project to "A Roman's Tale" and I'll be crediting Mageweaver01 and Dread_Dragon in the load screen as well as the quest menu as being the original creators.

Edit2: Just tested the new triggers and it functions well! I assume the leaks for this particular trigger have been fixed as well. Now... just another... 45 triggers to fix! :D
 
Last edited:
Level 3
Joined
May 15, 2011
Messages
30
Avoid leaks.

I guess what I'm trying to ask here is, how does making a variable equal to null help avoid leaks after destroying said variable?

Apologies for my ignorance, I'm relatively new to this and would love to learn not only how to do things, but also why it works the way it does.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
how does making a variable equal to null help avoid leaks after destroying said variable?

You do not destroy a variable, you destroy the object that is in the memory. Variables point to those objects. Variables hold the "address" of the object (group, location, unit etc.). Nulling makes the variable to not point anywhere.
 
Level 3
Joined
May 15, 2011
Messages
30
Thank you both, that makes a lot of sense! :)

Also, in your trigger Maker you didn't use an array. Is there a preference of using multiple variables over arrays? Or is using arrays fine for just ordinary triggering that doesn't necessarily NEED an array?
 
Level 20
Joined
Apr 14, 2012
Messages
2,901
I think it depends on the kind of trigger... because arrays are a powerful programming tool that allow the creation of more dynamic and simplified code. Once you understand their structure and usage, creating 'complicated' triggers will be well within reach. Just like a variable, arrays store data within them. Except that while a variable is like a cabinet, an array is more like a book with many pages.

Also arrays have many uses; for more info on arrays either go here: Triggers- Variables and Arrays or find some info on the Hive.
 
Status
Not open for further replies.
Top