| 02-05-2006, 07:33 AM | #1 |
Why doesn't the code below work. If I use a global variable as my toggle it's fine but it doesn't work with the Handle Variables. Code:
function Trig_Tidal_Fury_Toggle_Conditions takes nothing returns boolean
return GetUnitAbilityLevelSwapped('A007', GetTriggerUnit()) > 0
endfunction
function Trig_Tidal_Fury_Toggle_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if GetIssuedOrderId() == OrderId("immolation") then
call SetHandleBoolean(u, "TF", true)
elseif GetIssuedOrderId() == OrderId("unimmolation") then
call SetHandleBoolean(u, "TF", false)
endif
set u = null
endfunction
//===========================================================================
function InitTrig_Tidal_Fury_Toggle takes nothing returns nothing
set gg_trg_Tidal_Fury_Toggle = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Tidal_Fury_Toggle, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( gg_trg_Tidal_Fury_Toggle, Condition(function Trig_Tidal_Fury_Toggle_Conditions))
call TriggerAddAction( gg_trg_Tidal_Fury_Toggle, function Trig_Tidal_Fury_Toggle_Actions )
endfunctionCode:
function Trig_Tidal_Fury_Conditions takes nothing returns boolean
local unit u = GetTriggerUnit()
local unit t = GetAttacker()
return GetUnitAbilityLevelSwapped('A007', t) > 0 and GetHandleBoolean(u, "TF")
endfunction
function Trig_Tidal_Fury_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit t = GetAttacker()
local location p = GetUnitLoc(u)
call UnitDamagePointLoc( t, 0.01, ( 100.00 * I2R(GetUnitAbilityLevelSwapped('A007', t)) ), p, I2R(GetHeroStr(t, true)), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call CreateSpecialFXTimed( p, "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCasterOverhead.mdl", 3.00 )
call RemoveLocation( p )
set p = null
set u = null
set t = null
endfunction
//===========================================================================
function InitTrig_Tidal_Fury takes nothing returns nothing
set gg_trg_Tidal_Fury = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Tidal_Fury, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Tidal_Fury, Condition( function Trig_Tidal_Fury_Conditions ) )
call TriggerAddAction( gg_trg_Tidal_Fury, function Trig_Tidal_Fury_Actions )
endfunction |
| 02-05-2006, 08:03 AM | #2 |
Are you sure that you have the Set and GetHandleBoolean functions? |
| 02-05-2006, 08:06 AM | #3 |
Saying what kind of error you get would help. |
| 02-05-2006, 08:28 AM | #4 |
Code:
GetHandleBoolean(u, "TF") Code:
function Trig_Tidal_Fury_Conditions takes nothing returns boolean
local unit u = GetTriggerUnit()
local unit t = GetAttacker()
return GetUnitAbilityLevelSwapped('A007', t) > 0 and GetHandleBoolean(u, "TF")
endfunction |
| 02-05-2006, 08:56 AM | #5 |
In one condition, you make both the ability comparison and the local variable comparison on the same unit. In the other condition, you make one comparison on the attacker and one on the attacked unit... perhaps that's the problem? Can't be sure because I don't know what the spell is supposed to do. Also, you should nullify the unit local variables at the end of Trig_Tidal_Fury_Conditions. |
| 02-06-2006, 10:37 PM | #6 |
Its working now, thanks Anitarf, I had the retarted mistake of checking on the triggering unit not the attack one. The spell is meant to do damage, based on the heros intelect. Its based on immolation, and drains mana when active. The first trigger is to toggle between on/off for the unit. You can't and don't need to nullify when a function returns something. |
| 02-06-2006, 11:07 PM | #7 |
You really can't nullify a local if the function returns it, but that still doesn't mean you don't need to. Handle locals leak if not nullified, always. In your case, you can avoid the leak easily with an additional integer and boolean local variable, or by using the event responses directly in the return statement. Otherwise, you have to use the return bug or dummy parameters (parameters, unlike locals, don't cause this leak) to avoid this leak. |
