This is the code for an ability that doesn't really work
Explanation below the functions.
Using a dummy ability based on channel, units at random, filtered by the function Cond1 which is not written but has no problem, are supposed to be singularly picked up at 0.4sec intervals between one another. The number of units picked up is dependant on the ability level and should be at least 4. Each of the units picked is paused, a dummy unit for special effect is created on them and then.. the rest is not important, i still have to write it
Well it doesn't work, only one unit is picked up and then nothing.
Im guessing the problem(s) is in Pick_Act1, where the recursion is.. It is the first time I try it in jass so there might be something I don't know, or I might be simply stupid and have made an abomination
All I know is that using the ability only prints "ok" (ability condition check). After 4 casts it prints "ok", "done" and 0.5sec after "success", but i guess that is just because apparently the index i gets increased with each cast. Which is strange, because it means that the part inside the if should have been all executed at least once, but this is not true because "pAct1" is never printed. I really don't get this..
Because the whole thing wasn't working, i took away the timers to make the pick ups directly subsequent, thinking that may be a recursion with delays inside might have been the cause, but that wasn't the problem. Only 1 unit at random is picked up, the special effect dummy is created on it, and then nothing..
What's wrong?
It is also the first time I use a scope, is there something wrong with recursion and scopes?
Thanks in advance!
JASS:
scope AID
globals
unit cast = null
unit targ = null
real castx
real casty
location loc = null
group grp1
group grp2
real dmgcount = 0
integer i = 0
endglobals
function Actions2 takes nothing returns nothing
call ReleaseTimer(GetExpiredTimer())
call displ("success(or not?)")
endfunction
function Timed1 takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, 0.5, false, function Actions2)
set t = null
endfunction
// Pauses targets in range=1000 and saves their life + mana for final explosion, one by one every .4 seconds
function Pick_Act1 takes nothing returns nothing
//local timer t = CreateTimer()
//call ReleaseTimer(GetExpiredTimer())
set targ = GroupPickRandomUnit(grp1)
if (targ != null) and (i< 3+GetUnitAbilityLevel(cast, 'AID2')) then
set i = i+1
set loc = Location(GetUnitX(targ),GetUnitY(targ))
call CreateNUnitsAtLoc( 1 , 'h004', Player(PLAYER_NEUTRAL_PASSIVE), loc, 0) //special effect dummy
call SetUnitTimeScalePercent( GetLastCreatedUnit(), 40.00 )
call UnitApplyTimedLifeBJ( 1.00, 'BTLF', GetLastCreatedUnit() )
call PauseUnitBJ(true, targ)
set dmgcount = dmgcount + GetUnitState(targ, UNIT_STATE_LIFE) + GetUnitState(targ, UNIT_STATE_MANA)
call RemoveLocation(loc)
call GroupAddUnit(grp2,targ)
call GroupRemoveUnit(grp1,targ)
set targ = null
call displ("pAct1")
call Pick_Act1()
else
call displ("done")
set targ = null
call DestroyGroup(grp1)
call Timed1()
endif
//call TimerStart(t, 0.4, false, function Pick_Act1)
//set t = null
endfunction
//Initial function for this spell. Pauses caster and starts actions on targets
function Actions1 takes nothing returns nothing
set cast = GetTriggerUnit()
set castx= GetUnitX(cast)
set casty= GetUnitY(cast)
set loc = Location(castx,casty)
set grp1 = GetUnitsInRangeOfLocMatching(1000,loc, Filter(function Cond1))
call RemoveLocation(loc)
call SetUnitInvulnerable( cast, true )
call Pick_Act1()
endfunction
//Simply checks if the spell is the dummy for this ability
function Condition1 takes nothing returns boolean
call displ("ok")
return (GetSpellAbilityId()== 'AID2')
endfunction
//===========================================================================
function InitTrig_All_is_Dust_2 takes nothing returns nothing
set gg_trg_All_is_Dust_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_All_is_Dust_2, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerAddCondition( gg_trg_All_is_Dust_2, Condition(function Condition1 ))
call TriggerAddAction( gg_trg_All_is_Dust_2, function Actions1 )
endfunction
endscope
Using a dummy ability based on channel, units at random, filtered by the function Cond1 which is not written but has no problem, are supposed to be singularly picked up at 0.4sec intervals between one another. The number of units picked up is dependant on the ability level and should be at least 4. Each of the units picked is paused, a dummy unit for special effect is created on them and then.. the rest is not important, i still have to write it
Well it doesn't work, only one unit is picked up and then nothing.
Im guessing the problem(s) is in Pick_Act1, where the recursion is.. It is the first time I try it in jass so there might be something I don't know, or I might be simply stupid and have made an abomination
Because the whole thing wasn't working, i took away the timers to make the pick ups directly subsequent, thinking that may be a recursion with delays inside might have been the cause, but that wasn't the problem. Only 1 unit at random is picked up, the special effect dummy is created on it, and then nothing..
What's wrong?
It is also the first time I use a scope, is there something wrong with recursion and scopes?
Thanks in advance!