I am learning JASS and I made two versions of one spell (GUI and JASS version) and I do not understand why the former doesn't work properly.
My spell reads like this:
'Choose a unit. In ten seconds the chosen unit will die'
First version:
===================================
Event:
- Unit casts a spell
Condition:
- Ability being cast is KILL
Actions:
- Set VICTIM = TargetUnitOfAbilityBeingCast
- Wait 10 seconds
- Kill VICTIM
====================================
So clearly when you cast the spell two times on two different units within the 10 seconds period, only the second target dies because the value VICTIM is being overwritten every time you cast the spell.
But this code in JASS with basically the same contents works fine:
Second version:
Even if I cast this on two units, both die in10 seconds. For some reason the local 'u' does not overwrite itself and I don't know why it works like this. Why is that so?
Do I have to also add set u = null in the end of my function to avoid leaks?
Also, I rarely see the "Wait" command in other people's spells however I find it useful and I cannot do without it especially when making a consequence of special effects. Is "wait" bad or not?
// P.S.:
How do I make different triggers with each having its own event and condition within a single document? Like in GUI you had one document per trigger, can I put them all in one with JASS?
// P.P.S:
Can I refer to other documents when using JASS? I mean do they share variables (at least globals)? Can I turn on or off other 'trigger documents' or call funcitons from them? Or it works some other way?
My spell reads like this:
'Choose a unit. In ten seconds the chosen unit will die'
First version:
===================================
Event:
- Unit casts a spell
Condition:
- Ability being cast is KILL
Actions:
- Set VICTIM = TargetUnitOfAbilityBeingCast
- Wait 10 seconds
- Kill VICTIM
====================================
So clearly when you cast the spell two times on two different units within the 10 seconds period, only the second target dies because the value VICTIM is being overwritten every time you cast the spell.
But this code in JASS with basically the same contents works fine:
Second version:
Code:
function Trig_Kill_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Trig_Kill_Actions takes nothing returns nothing
local unit u = GetSpellTargetUnit()
call TriggerSleepAction(10)
call KillUnit(u)
endfunction
//===========================================================================
function InitTrig_Kill takes nothing returns nothing
set gg_trg_Kill = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Kill, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition (gg_trg_Kill, Condition (function Trig_Kill_Conditions))
call TriggerAddAction( gg_trg_Kill, function Trig_Kill_Actions )
endfunction
Even if I cast this on two units, both die in10 seconds. For some reason the local 'u' does not overwrite itself and I don't know why it works like this. Why is that so?
Do I have to also add set u = null in the end of my function to avoid leaks?
Also, I rarely see the "Wait" command in other people's spells however I find it useful and I cannot do without it especially when making a consequence of special effects. Is "wait" bad or not?
// P.S.:
How do I make different triggers with each having its own event and condition within a single document? Like in GUI you had one document per trigger, can I put them all in one with JASS?
// P.P.S:
Can I refer to other documents when using JASS? I mean do they share variables (at least globals)? Can I turn on or off other 'trigger documents' or call funcitons from them? Or it works some other way?