| 03-25-2007, 06:11 PM | #1 |
JASS:function Check takes nothing returns boolean if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true then return true else return false endif endfunction function Damage_Starving_Unit takes nothing returns nothing local unit u = GetEnumUnit() local real mana = GetUnitState(u, UNIT_STATE_MANA) local real life = GetUnitState(u, UNIT_STATE_LIFE) if mana < 1.00 then call SetUnitState( u, UNIT_STATE_LIFE, life - 5.) endif set u = null endfunction function Starvation_Actions takes nothing returns nothing local rect r = GetPlayableMapRect() local group g = GetUnitsInRectMatching(r, Condition(function Check)) call ForGroup(g , function Damage_Starving_Unit ) call RemoveRect(r) call PolledWait(.1) call DestroyGroup(g) set r = null set g = null endfunction //=========================================================================== function InitTrig_Starvation takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterTimerEventPeriodic(t, 2.50 ) call TriggerAddAction(t, function Starvation_Actions ) set t = null endfunction Not sure why it won't work. In fact, alot of things don't like to work for me. Basically anything involving timers/groups with callback functions will throw my stuff crazy, which really limits my possibilites with spell making. Can anyone see what's making this not work? It might clue me in as to why a bunch of my other triggers didn't want to work. |
| 03-25-2007, 07:32 PM | #2 |
GetPlayableMapRect returns a bj global rect, which you then remove. So after the first time that runs, your rect will be null. Just remove the RemoveRect call. |
| 03-25-2007, 08:01 PM | #3 |
Always feeling the need to point things out... JASS:function Check takes nothing returns boolean if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true then return true else return false endif endfunction JASS:function Check takes nothing returns boolean return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) endfunction And now I have a question: if I did something like this, would it leak a rect?: JASS:local group g = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function SomeFunc)) |
| 03-25-2007, 09:38 PM | #4 |
That shouldn't leak. That function only returns a predefined rect, so using it like that shouldn't cause a leak. You're not creating a losing a rect by calling that, nor are you setting it to a local variable. It'd basically be like doing this: JASS:local group g = GetUnitsInRectMatching(bj_mapInitialPlayableArea, Condition(function SomeFunc)) And besides that, it's a global constant in most cases I can think of. |
| 03-25-2007, 09:49 PM | #5 |
You should clean the boolexp for Condition(). Just set it to a local variable and destroy it after. Easy enough. |
| 03-25-2007, 09:54 PM | #6 |
@pyrogasm: I know it's supposed to be what you replaced it with, but because it was a conditition i hadn't worked with before, i was unsure how to work it. Thanks for that. @Blu: Are you serious? My problems have been coming up with groups because I've been removing the rects? Wow, thanks! But... What about rects that don't return a bj global? Do i just not remove the rects? But then... that would leak, wouldn't it? |
| 03-25-2007, 10:45 PM | #7 | |
If you're worried about it, you could get the rect max/min X and Y and create a new rect then you can destroy that rect without any harm in destroying the original. Quote:
|
| 03-25-2007, 10:49 PM | #8 | |
Quote:
http://www.wc3jass.com/viewtopic.php?t=2370 |
| 03-25-2007, 10:54 PM | #9 |
Good find Alevice, I'll fix my script accordingly. |
| 03-26-2007, 12:28 AM | #10 |
o.O I didn't know that, Alevice. Is it only for UNIT_TYPE_TOWNHALL, or all unit-types? |
| 03-26-2007, 01:06 AM | #11 |
JASS:function InitTrig_Starvation takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterTimerEventPeriodic(t, 2.50 ) call TriggerAddAction(t, function Starvation_Actions ) set t = null endfunction Replace that with -- JASS:function InitTrig_Starvation takes nothing returns nothing call TimerStart(CreateTimer(), 2.5, true, function Starvation_Actions) endfunction |
| 03-26-2007, 01:22 AM | #12 |
Will do. Thanks... But does that leak a timer? God, everything is so confusing tonight. |
| 03-26-2007, 01:29 AM | #13 |
Your original function had that trigger running for the entire length of the game. My replacement function has a timer that runs for the entire length of the game. If you ever want to stop/destroy it for whatever reason, set it to a global variable and destroy it as necessary. Things that should exist for the whole game aren't leaks. |
| 03-26-2007, 01:31 AM | #14 |
Im relativly sure it will not leak a timer if you destroy the timer when it expires. |
| 03-26-2007, 01:34 AM | #15 | |
Quote:
That isn't a leak at all. In his original code he posted, he didn't destroy the trigger after a single iteration, so why would he want to destroy the timer after one iteration? They serve the same purpose; heck, the periodic triggers USE timers internally. This just saves the extra steps. |
