• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Trigger] Does this trigger leak?

Status
Not open for further replies.
Level 9
Joined
Oct 24, 2007
Messages
421
Hey hive.... Just iron out some leaks in my map. Items drop VERY often in my map so I want to remove these triggers of leaks if possible. I've used destroy scripts for the very first time and was wondering does the trigger in the image provided leak at all, and have the destroy scripts been written and placed properly?

EDIT: Also added one more trigger with leaks hopefully removed. Advice on if this is right is also needed.

(both of these triggers work with even the new leaks removed so I assume they're OK but just making sure)
 

Attachments

  • goldrops3.JPG
    goldrops3.JPG
    59.8 KB · Views: 128
  • and this one.JPG
    and this one.JPG
    113.8 KB · Views: 112
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
Use [trigger] code [/trigger] tags please.

Your first (left) code doesn't leak, but you should remove all those Do Nothing's.
You should also put your if's in a nested way, because right now all the conditions are checked even if one was already right.
The way it should be to improve performance is
Code:
if con1 then
elseif con2 then
elseif con3 then
elseif con4 then
endif

You could also sort it by which condition is the most likely to happen, then the next condition which is most likely to happen etc., if you really want to.


Your second code leaks a lot of locations.
Position of unit returns a location.

It should be something like this:
Code:
Loc1 = Position of X
Loc2 = Loc1 offset by Y

Also notice that you are getting and setting three times the exact same locations.
You should just set two location variables to each of those, use them, and destroy them at the end.

You could also put your second code in a tiny loop instead of writing the same actions again and again.
 
Level 9
Joined
Oct 24, 2007
Messages
421
Thanks for your advice Ghostwolf, was very informative and I felt your genuine interest to help me, much appreciated +rep

And a useful application there too Mechanical man +rep

I think these are fixed now....
 

Attachments

  • fixed1.JPG
    fixed1.JPG
    99.6 KB · Views: 115
  • fixed2.JPG
    fixed2.JPG
    61.6 KB · Views: 117
Level 29
Joined
Jul 29, 2007
Messages
5,174
Again, notice that you are still setting the third location and removing it three times.
You could just set it at the start (and you could even just replace the first location with it), and remove it at the end.
Something like this:
  • Set loc1 = Position of X
  • Set loc2 = loc1 offset by...
  • Custom script: call RemoveLocation(loc1)
  • Set loc1 = loc2 offset by...
  • All your code
  • Custom script: call RemoveLocation(loc1)
  • Custom script: call RemoveLocation(loc2)
And like I said, you can put all the creating/ordering units in a loop. It sure will make codes of this type nicer, and nice and neat codes = awesome.

In case you do not know how to use loops, use this action (about the 10th action or so):
  • For each (Integer A) from 1 to 10, do (Actions)
    • Loop - Actions
This will run 10 times (every time the A integer you see in the action will be set to "A = A + 1" untill it gets to 10, and the 1 tells that A will be initialized with the value of 1).
This is very useful for repeating actions, even without mentioning the "Integer A" action that allows you to check the value of A, so for instance you could create a unit at "X + Integer A" in a loop and it will create each unit in a slightly different location.

That's about it for loops in GUI.
 
Level 13
Joined
May 11, 2008
Messages
1,198
actually the screen shots don't really bother me...scrolling around the trigger tags if they're too fat or too short sucks though imo.

anyway so the nested conditions is usually better huh? i'll have to convert some of my triggers to that style then it seems...
 
Level 5
Joined
Oct 17, 2006
Messages
151
Actually yixx what you posted up there is the wrong formula... It should look like this:

  • For each (Integer A) from 1 to 4, do (Actions)
    • Loop - Actions
      • If (all conditions are true) are true then do (then actions) Else do (else actions)
        • Condition:
          • Integer A = (Goldinteger)
        • Then:
          • Item - Create (2^(Integer A)) gold items @ Loc
        • Else:
The result would be:

2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
In case you STILL didn't get it, they are different items.

anyway so the nested conditions is usually better huh? i'll have to convert some of my triggers to that style then it seems...

They will always statistically be better.

Instead of checking X conditions every call, you only check Y conditions, which depends on some factors including the chances for each condition, the order you put them in, and some other things which I can't think of right now.

If all the conditions have the same chances to happen, you will statistically check 50% of the conditions.

In case you do have different chances, the most efficient way is to put them in a linear order of chances:
Code:
con1 has 50% to happen
con2 has 8% to happen
con3 has 20% to happen
con4 has 10% to happen
con5 has 12% to happen

if con1 then
elseif con3 then
elseif con5 then
elseif con4 then
elseif con2 then
endif
 
Level 5
Joined
Oct 17, 2006
Messages
151
@Yixx; neavea
Where have you seen this function?
As I know CreateNItemsAtLoc exists neither on GUI nor on Jass.
You can create only 1 item, and if you need to create several items, you need loops.

Meh I knew there was something funny when I wrote the example up... Srry want at my pc at the time so I couldn't check it.

And ghostwolf are you talking to me?
 
Level 8
Joined
Aug 4, 2006
Messages
357
so for your item trigger, you could do:

  • Events
    • Unit - A unit owned by Player 11 (Dark Green) Dies
  • Conditions
  • Actions
    • Set tempointgold = (Position of (Triggering unit))
    • Set goldinteger = (Random integer number between 1 and 10)
    • For each (Integer A) from 1 to (Integer((Power(2.00, goldinteger)))), do (Actions)
      • Loop - Actions
        • Item - Create gold at tempointgold
    • Custom script: call RemoveLocation(udg_tempointgold)
By the way, I'm looking forward to your diablo 2 map. I might play it this weekend.
 
Status
Not open for further replies.
Top