| 02-27-2008, 11:41 PM | #1 | ||
How do you "loop" functions where a function on the top of the script can call on one thats on the bottom?
What I'm trying to do is replicate Halo's concept of shield recharge. Brief Description: If you take a hit, you heal your shield back after # seconds. If you take another hit, the timer starts over, and your recharge is halted. My trigger does everything, except one part of it is messed. If you take a hit while your recharging, your shield doesn't regen until you get hit again. So, that's why I'm trying to "loop" it I guess. Also, I'm not sure about my code's efficiency... |
| 02-28-2008, 12:10 AM | #2 |
Actions() is a private function, you would need to make it public or don't use any access modifier, them you can call it through call ExecuteFunc( "Actions" ) |
| 02-28-2008, 12:13 AM | #3 | |
Quote:
Edit: I just realized calling actions isn't going to help. So...what can I do to get the effect I want? |
| 02-28-2008, 12:16 AM | #4 |
So, use ExecuteFunc and you are done |
| 02-28-2008, 12:40 AM | #5 |
Just tried, it doesn't work. |
| 02-28-2008, 12:52 AM | #6 |
The game crashed? Did you try ExecuteFunc( "Shield_Actions" )? |
| 02-28-2008, 01:40 AM | #7 |
No, it doesn't crash, it doesn't do anything, mainly since GetTriggerUnit() would be null...along with the dmg source. |
| 02-28-2008, 08:09 AM | #8 | |
ExecuteFunc passes event responses as far as I know, so... you might have to make "Actions" a public function or give it a unique name that you can call with ExecuteFunc. Maybe there's something with the SCOPE_PRIVATE prefix. I'd check the JASSHelper Manual. If you really want to call Actions I'd do something like this instead: JASS:private function Callback takes nothing returns boolean local shield dat = TT_GetData() local real mana = GetUnitState(dat.a, UNIT_STATE_MANA) if HEALING[dat.pui] then call SetUnitState(dat.a, UNIT_STATE_MANA, mana+REGEN_INTERVAL) call DestroyEffect( AddSpecialEffectTarget( REGEN_EFFECT, dat.a, "chest" ) ) if mana >= MAX_SHIELD then call SetWidgetLife(dat.a, GetUnitState(dat.a, UNIT_STATE_MAX_LIFE)) set HEALING[dat.pui] = false return true endif if STOP[dat.pui] then return true set HEALING[dat.pui] = false call ExecuteFunc("ShieldThing123123") endif else return true endif return false endfunction //=========================================================================== private function Delay takes nothing returns boolean local shield dat = ABCT_GetData() if GetWidgetLife(dat.a) > 0.406 and not STOP[dat.pui] and not HEALING[dat.pui] then set HEALING[dat.pui] = true call SetWidgetLife(dat.a, GetUnitState(dat.a, UNIT_STATE_MAX_LIFE)) call DestroyEffect( AddSpecialEffectTarget( REGEN_START, dat.a, "overhead" ) ) call TT_Start(function Callback, dat) elseif STOP[dat.pui] then set HEALING[dat.pui] = false endif return true endfunction //============================================================================== private function Actions takes nothing returns nothing local unit a = GetTriggerUnit() local integer PUI = GetUnitIndex(a) local real mana = GetUnitState(a, UNIT_STATE_MANA) local real damage = GetEventDamage() local timer t = NewTimer() if not HEALING[PUI] then set STOP[PUI] = false call ABCT_Start(function Delay, shield.create(a, PUI), REGEN_DELAY ) elseif HEALING[PUI] then set STOP[PUI] = true endif set a = null endfunction function ShieldThing123123 takes nothing returns nothing //Just some name you know that definitely won't conflict with anything call Actions() //This allows you to keep Actions a private function endfunction Ah... here's what the JASSHelper manual has to say: Quote:
JASS:private function Callback takes nothing returns boolean local shield dat = TT_GetData() local real mana = GetUnitState(dat.a, UNIT_STATE_MANA) if HEALING[dat.pui] then call SetUnitState(dat.a, UNIT_STATE_MANA, mana+REGEN_INTERVAL) call DestroyEffect( AddSpecialEffectTarget( REGEN_EFFECT, dat.a, "chest" ) ) if mana >= MAX_SHIELD then call SetWidgetLife(dat.a, GetUnitState(dat.a, UNIT_STATE_MAX_LIFE)) set HEALING[dat.pui] = false return true endif if STOP[dat.pui] then return true set HEALING[dat.pui] = false call ExecuteFunc(SCOPE_PRIVATE+"Actions") endif else return true endif return false endfunction //=========================================================================== private function Delay takes nothing returns boolean local shield dat = ABCT_GetData() if GetWidgetLife(dat.a) > 0.406 and not STOP[dat.pui] and not HEALING[dat.pui] then set HEALING[dat.pui] = true call SetWidgetLife(dat.a, GetUnitState(dat.a, UNIT_STATE_MAX_LIFE)) call DestroyEffect( AddSpecialEffectTarget( REGEN_START, dat.a, "overhead" ) ) call TT_Start(function Callback, dat) elseif STOP[dat.pui] then set HEALING[dat.pui] = false endif return true endfunction //============================================================================== private function Actions takes nothing returns nothing local unit a = GetTriggerUnit() local integer PUI = GetUnitIndex(a) local real mana = GetUnitState(a, UNIT_STATE_MANA) local real damage = GetEventDamage() local timer t = NewTimer() if not HEALING[PUI] then set STOP[PUI] = false call ABCT_Start(function Delay, shield.create(a, PUI), REGEN_DELAY ) elseif HEALING[PUI] then set STOP[PUI] = true endif set a = null endfunction |
| 02-28-2008, 09:48 AM | #9 | |
Quote:
Also, it's called recursion, not looping. Best way to do it would be using the .evaluate mechanic with a function interface, not ExecuteFunc. |
| 02-28-2008, 09:51 AM | #10 |
Does .evaluate pass event responses? |
| 02-28-2008, 09:58 AM | #11 |
I'm not sure, but he doesn't have any to begin with because Callaback is run by a timer, not by a trigger. |
| 02-28-2008, 07:21 PM | #12 |
Oh, I see. |
