• 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.

Unit dies in region

Status
Not open for further replies.
Level 4
Joined
Apr 16, 2012
Messages
83
I want to make it so that when a unit-type in a specific region dies, it adds 1 to an integer variable. Is this possible?
 
Level 4
Joined
Apr 16, 2012
Messages
83
Hmm, how would I do this? I searched for such a method and I can't find it. Maybe I'm overlooking something simple. Humour me, I'm a World Editor noob!

Edit: Found the solution I believe. It's below just in case another unexperienced user like me wants to use this sort of method!

  • Unit - A unit Dies
  • (Forest Area 1 <gen> contains (Dying unit)) Equal to True
  • Set Forest1Reset = (Forest1Reset + 1)
(Its in Boolean Comparison)
 
Level 5
Joined
Dec 12, 2011
Messages
116
It's very simple. Here you go:

  • UnitType Dies in Region
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to UNIT_TYPE_YOU_WANT
      • (REGION_YOU_WANT contains (Position of (Triggering unit))) Equal to True
    • Actions
      • Set VARIABLE_YOU_WANT = (VARIABLE_YOU_WANT + 1)
This trigger has a memory leak, though. It means that it will create a small lag in your map (really really small, only noticeable if you run this, let's say, 200 times).

You said that you are a World Editor noob. So, you shouldn't start worrying about cleaning memory leaks, but I'll explain it a bit to you, so you won't be that noob anymore.

OBS: Your problem is already solved. Use the trigger above and it will work. Read more to learn more about the World Editor.

There are some "objects" that generate memory leaks. They are Points, Regions, Unit Groups and Player Groups.

When we do (Position of (Triggering unit)) inside another function, we are creating a memory leak. To solve it, we must put that into a variable first, use the variable at the functions we want, and then "destroy the variable"! This will clean the leak. Look at the following trigger:

  • UnitType Dies in Region No Leak
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Playable map area) contains TempPoint) Equal to True
        • Then - Actions
          • Set YO = (YO + 1)
        • Else - Actions
      • Custom script: call RemoveLocation( udg_TempPoint )
The script does not leak anymore. You may be wondering "wtf is that last function":
  • Custom script: call RemoveLocation( udg_TempPoint )
This is a Custom Script function, that allows us to use JASS functions inside the GUI area. GUI is the interface you use to create the triggers. There is another way to program things, it's using JASS. JASS stands for Just Another Scripting Syntax (LOL) and it's the Warcraft 3's programming language that mapmakers use. Actually, every trigger you do within GUI is converted to JASS at the moment you save your map.

So, the function we need to call to remove the leak, unfortunately, can't be accessed through GUI. We need a Custom Script action to do that (it is the third action in the big action list). That function takes a point variable as parameter (it's the udg_TempPoint that appears inside those parenthesis). In JASS, all global variables declared in GUI receive an udg_ prefix. As "CustomScript" action is actually a JASS call, we need to manually put that prefix.

And, what does that RemoveLocation() function exactly do? It's very simple, it cleans the point leak saved into the udg_TempPoint variable. In that moment, the leak is cleaned. OBS: If you try to use the TempPoint variable after that CustomScript, it will not act as "(Position of (Triggering unit))" anymore. When the "leak was destroyed", actually the information of the point was destroyed, so, obviously, it can't be accessed anymore.

The variable still exists, though. You can set new values to it, and it will work.


Anything you didn't understand, please ask.

hamsterpellet
 
Status
Not open for further replies.
Top