Adding destructibles to a group

TDN

New Member
Reaction score
3
I have a map that spawns trees randomly when a condition is met. Later on I want the trees to be removed when the condition is met again, but I don't want any preset trees to be removed.

Is it possible to add destructibles to a group as they are created, so that I can later delete all destructibles within that group?
 

Necrach

You can change this now in User CP.
Reaction score
62
I do not have the editor to answer your question, but you could create a dummy unit by the position of each spawned tree, and then destroy all destructibles within 0.1 range of any such dummy
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
you can make an index system to save the trees inside an array. like, each time you create a tree you increase an integer variable and save the unit as Trees[Integer] = (LastCreatedDestructible) and if you want to remove them all go with an forLoopIntegerA iteration.
 

TDN

New Member
Reaction score
3
Sounds like it should work, but I've hit a bit of a snag - trees aren't being placed at all. Here's the trigger:

Trigger:
  • Tree spawns
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Set Tree_Increments = 1
      • For each (Integer A) from 1 to 200, do (Actions)
        • Loop - Actions
          • Destructible - Remove Tree_Count[(Integer A)]
      • For each (Integer A) from 1 to 50, do (Actions)
        • Loop - Actions
          • Set Location = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Terrain cliff level at Location) Greater than 1
                  • (Town <gen> contains Location) Equal to False
            • Then - Actions
              • Set TreeScale = (Random real number between 0.85 and 1.10)
              • Set TreeVariation = (Random integer number between 1 and 3)
              • Set SpawnSize = (Random integer number between 1 and 5)
              • For each (Integer A) from 1 to SpawnSize, do (Actions)
                • Loop - Actions
                  • Destructible - Create a Summer Tree Wall at (Location offset by 35.00 towards (Random angle) degrees) facing (Random angle) with scale TreeScale and variation TreeVariation
                  • Set Tree_Count[Tree_Increments] = (Last created destructible)
                  • Set Tree_Increments = (Tree_Increments + 1)
            • Else - Actions
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
first of all, why do you run this iteration from 1 to 200? you create about 50 - 250 trees, that means either you run it too often or not often enough.
Trigger:
  • For each (Integer A) from 1 to 200, do (Actions)
    • Loop - Actions
      • Destructible - Remove Tree_Count[(Integer A)]


this conditions might not be met:
Trigger:
  • If - Conditions
    • And - All (Conditions) are true
      • Conditions
        • <b>(Terrain cliff level at Location) Greater than 1</b>
        • (Town &lt;gen&gt; contains Location) Equal to False

are you sure the cliff level is greater then 1?

and finally this action is leaking a point variable:
Trigger:
  • Destructible - Create a Summer Tree Wall at <b>(Location offset by 35.00 towards (Random angle) degrees)</b> facing (Random angle) with scale TreeScale and variation TreeVariation

with that offset function you are creating another point variable which is leaking.
 

TDN

New Member
Reaction score
3
I'm randomizing the SpawnSize variable between 1 and 5, so that's potentially 50 x 5 trees - I should actually be running 250 removal iterations in the beginning instead of 200.

I disabled both conditions, still no luck. Yes the cliff level is greater than one, since other triggers running that check work fine.

I need the offset, otherwise when I create groups of 2 - 5 trees they'll end up right on top of each other, surely? Anyhow I'm not sure how to fix that leak.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Trigger:
  • Tree spawns
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Set Tree_Increments = 1
      • For each (Integer A) from 1 to 250, do (Actions)
        • Loop - Actions
          • Destructible - Remove Tree_Count[(Integer A)]
      • For each (Integer A) from 1 to 50, do (Actions)
        • Loop - Actions
          • Set Location = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Terrain cliff level at Location) Greater than 1
                  • (Town &lt;gen&gt; contains Location) Equal to False
            • Then - Actions
              • Set TreeScale = (Random real number between 0.85 and 1.10)
              • Set TreeVariation = (Random integer number between 1 and 3)
              • Set SpawnSize = (Random integer number between 1 and 5)
              • For each (Integer B) from 1 to SpawnSize, do (Actions)
                • Loop - Actions
                  • set TempPoint = (Location offset by 35.00 towards (Random angle) degrees)
                  • Destructible - Create a Summer Tree Wall at TempPoint facing (Random angle) with scale TreeScale and variation TreeVariation
                  • Set Tree_Count[Tree_Increments] = (Last created destructible)
                  • Set Tree_Increments = (Tree_Increments + 1)
                  • custom script: call RemoveLocation (udg_TempPoint)
            • Else - Actions
          • custom script: call RemoveLocation (udg_Location)

this is how it should look like to avoid memory leaks.
I also noticed you used an integer A iteration inside an integer A iteration, thats not good, i changed the second one to integer B.

to fix your problem you should try adding some debug messages and test where the problem might be.
good luck.
 

TDN

New Member
Reaction score
3
Thanks, it seems to work perfectly, the error was surely the use of an Integer A loop inside another Int. A loop. I can't believe I didn't see that before, I was so busy going through other checks that I missed it ><

I'm curious as to why you destroy both variables TempPoint and Location at the end. I know they leak, but I'll be re-using them constantly throughout the game, and each time they are used they over-write the leak. I would understand if it's a size 1000 array that you are destroying, but a single variable leak that is constantly re-used?
 

Azylaminaz

Vox Populi
Reaction score
91
It isn't cleaned when it is reused, it's just defined in another location and the reference to the first is lost.

Only non-primitive types do this, such as units, locations, groups, forces, special effects.... etc. Primitives do redefine in the same space (reals, integers, etc).
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
[...]
I know they leak, but I'll be re-using them constantly throughout the game, and each time they are used they over-write the leak. I would understand if it's a size 1000 array that you are destroying, but a single variable leak that is constantly re-used?

i think you didnt understand how leaks work.
if you set a variable the stuff saved inside the variable takes up some memory.
if you clear the variable (like with removelocation, destroyGroup, whatsoever) you free the memory.
but if you set the variable, without removing the first saved object, to something else again you still have both objects saved, both objects take some of your memory but the first one cannot be removed again because you lost the reference with saving something else in the variable.
thats a memory leak.
that means, whenever you re-set a point/unitgroup/force/rect/etc variable without removing its reference before you leak memory.
 

TDN

New Member
Reaction score
3
Wow that's completely retarded lol. You'd wonder why the devs at Blizzard didn't have some or most leaks automatically removed. They did such a sloppy job with the GUI editor as well, so much so that there's even a topic floating around allowing the creation of new GUI commands.

Too bad there isn't a better editor in existence; I may try Starcraft 2 but I haven't much hope for it having anything other than a post-modern 'look'.

Yeah I'll definitely be including destroying the variables if they chain-leak like that. :thup:
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
actually i believe the wc3 world editor aint bad at all, just imagine how much you can do with it. i remember the map editor of, lets say command and conquer red alert, compared to the world editor of wc3 that was peanuts.

i think the problem lies within blizzard's lazyness, or maybe they just didnt thought the world editor would become this famous and favoured. Maybe they thought it wouldnt be used that much and didnt introduced that much "in-depth" functions.

however i heard the galaxy editor (of starcraft 2) is alot better then the world editor, with many many new features which where missing in the world editor, like a generic "unit takes damage" event.
i heard it though, might be wrong.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top