• 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] Do these triggers leak?

Status
Not open for further replies.
Level 12
Joined
Feb 13, 2009
Messages
388
Hello. I plan to use this "system" to spawn various units and order them to attack random player heroes. Since I will use it a lot I want to know what should I fix here to prevent leaks and optimize the structure.

  • Dogs
  • Events
    • Time - Every 41.00 seconds of game time
  • Conditions
  • Actions
    • Set dogloc1 = (Center of desertSpawn <gen>)
    • Set creepTarget = (Position of (Random unit from (Units in outside <gen> owned by (Random player from (All players controlled by User player)))))
    • For each (Integer A) from 1 to 10, do (Actions)
      • Loop - Actions
        • Unit - Create 1 |cffffcc00Wild dog for Player 11 (Dark Green) at dogloc1 facing Default building facing (270.0) degrees
        • Unit - Order (Last created unit) to Attack-Move To creepTarget
    • Custom script: call RemoveLocation(udg_dogloc1)
    • Custom script: call RenoveLocation(ung_creepTarget)
Also sometimes for some reason the spawned dogs don't pick targets, they just sit where spawned (at least in singleplayer, I guess it comes from random because there're no more players controlled by user to choose from, can you help me to solve this?).
So to prevent them hoarding at 1 place and to move those whos target is dead/hidden I use this "re-acquire target" script (via custom value 23).

14.59 seconds: to prevent conflicts with spawning scripts
  • Send23wave
  • Events
    • Time - Every 14.59 seconds of game time
  • Conditions
  • Actions
    • Set creepTarget = (Position of (Random unit from (Units in outside <gen> owned by (Random player from (All players controlled by a User player)))))
    • Unit Group - Pick every unit in (Units in outside <gen> owned by Player 11 (Dark Green)) and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Custom value of (Picked unit)) Equal to 23
          • Then - Actions
            • Unit - Order (Picked unit) to Attack-Move To creepTarget
          • Else - Actions
            • Do nothing
    • Custom script: call RemoveLocation(udg_creepTarget)
Any suggestions are highly appreciated.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Yes, they leak.

Set creepTarget = (Position of (Random unit from (Units in outside <gen> owned by (Random player from (All players controlled by User player)))))

Units in outside <gen> owned by (...) leaks a unit group.
All players controlled by User player leaks a player group

The fix:
Set tmp_force = All users controlled by a user player
Set tmp_group = Units in outside <gen> owned by tmp_force
set tmp_loc = Position of (random unit from tmp_group)
Custom script: call DestroyGroup(udg_tmp_group)
Custom script: call DestroyForce(udg_tmp_force)

Same for your second trigger.

EDIT: someone was faster, but " Custom script: set bj_wantDestroyGroup=true" will not solve your leak.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
But i once did a spell, and it worked perfectly first time, at the end of the spell i destroyed a unit group, and it wouldnt run anymore (not the way it meant to),,
So i said: Clear group, instead of DestroyGroup(udg_thing),, Then it would work serveral times,,
So tell me, why would you destroy groups if you want to use them more times?
I know they leak, but otherwise you cant use them anymore,, Or you have to localize the global, it would work then =)
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Because most, if not all, gui group actions automatically create group handles instead of clearing a group and adding new units to them. Unless you're using jass to enumerate units and group recycling, you will most probably leak.

If your trigger doesn't run anymore because you're destroying a group then it's a bug in your trigger, and not in destroying groups. The bug is probably caused by not knowing what actually happens when you use a certain GUI action.

In this trigger, you destroy your group or you leak. Simple as that.
 
Level 12
Joined
Feb 13, 2009
Messages
388
Yes, they leak.



Units in outside <gen> owned by (...) leaks a unit group.
All players controlled by User player leaks a player group

The fix:
Set tmp_force = All users controlled by a user player
Set tmp_group = Units in outside <gen> owned by tmp_force
set tmp_loc = Position of (random unit from tmp_group)
Custom script: call DestroyGroup(udg_tmp_group)
Custom script: call DestroyForce(udg_tmp_force)

Same for your second trigger.

EDIT: someone was faster, but " Custom script: set bj_wantDestroyGroup=true" will not solve your leak.

A question: which function destroys trigger variable? I.e. if I assign a variable to a unti and do something. DestroyUnit(udg_variable) is not working...
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
call RemoveUnit(udg_unitvar), which is the same as the "Unit - remove unit" GUI action.
Other methods to remove units from the game include "Kill unit" and "Add expiration timer".

To destroy triggers, you use DestroyTrigger(trigger var). However, it is not recommended you use this function. In general, let triggers leak when you no longer need them.
 
Level 5
Joined
Jan 25, 2006
Messages
103
Set creepTarget = (Position of (Random unit from (Units in outside <gen> owned by (Random player from (All players controlled by User player)))))
this should be changed, since it may cause troubles

avoid using random units and random players. instead base it on ally of player or integer from 1 to 10 count living units ally of player 1, etc...
no wonder why the dogs ain't attacking players.
 
Level 12
Joined
Feb 13, 2009
Messages
388
This is the thing I want to know how to do better to achieve the result :).

So basically creepTarget should be a point where the unit stands. And the unit is picked from the heroes controlled by players only. The effect: there's action around players, the spawned units go to wherever players are wandering and give them some xp/pain. What should I do here to pick the location without "causing troubles"?

Should I count the number of living players, then randomize it and pick from them? However note that the selection should be done between units only in outside <gen> so various units which are in buildings/underground are not affected.

P.S. Also I think I know how should I do. In the beginning, when each player trains a hero, I assign this hero to playerHero[index number of (owner of the last created unit)] and then I will randomize the max. length of this array to attack heroes only, does it sound like a right way to do it?
 
Status
Not open for further replies.
Top