HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

creating triggers ingame problem

03-25-2004, 12:58 AM#1
jardragon901
Grr, I'm trying to pass a local variable off to a trigger that is created and destroyed ingame. the variable I'm trying to pass off is a local real variable. Would I use add an event. I have an idea i could use a global array(one block for ech player) and send an event(like say a spell is cast, because it is being cast) then get the owner of the casting units player id and use that to get the variable array index[playerid#]. that would be a lot of work but I guess I would have to do it unless you guys have a better idea.
03-25-2004, 06:23 AM#2
KaTTaNa
Try to put these functions into the map header.
To pass the local variable, you do something like this:
Code:
local trigger trg = [i]whatever[/i]
local real var = [i]something[/i]
call SetHandleReal(trg, "localvar", var)
call TriggerExecute(trg)

....
[i]Inside your trigger[/i]
local real var = GetHandleReal(GetTriggeringTrigger(), "localvar")

Should work like a charm.
03-25-2004, 11:22 AM#3
jardragon901
Thank you so much, I feel like such a n00b for not checking the vault first.
03-25-2004, 12:47 PM#4
jardragon901
Well it would have worked if I didn't have to pass an integer also, the integer functions keep giving me compile errors because I am also sending the ablity code of the spell also.

the function I'm calling from one trigger
Code:
function rcac takes unit caster, integer abilid, real wait returns nothing
  local trigger trg=gg_trg_cwfec  
  local unit u=caster
  local integer i=abilid
  local real w=wait
    call SetHandleHandle( trg, "u", u)
    call SetHandleInt( trg, "i", i)
    call SetHandleReal( trg, "w", w)
    call TriggerExecute( trg)
endfunction


the trigger that is being executed(or is supposed to be)by the function
Code:
function Trig_cwfec_Actions takes nothing returns nothing
 local unit caster=GetHandleHandle(GetTriggeringTrigger(), "u")
 local integer abilid=GetHandleInt(GetTriggeringTrigger(), "i")
 local real delay=GetHandleReal(GetTriggeringTrigger(), "w")
    loop
        exitwhen GetUnitCurrentOrder(caster) == 0
        call TriggerSleepAction(0)
    endloop
    call UnitRemoveAbility( caster, abilid)
    call PolledWait(delay)
    call rc( caster)
endfunction

//===========================================================================
function InitTrig_cwfec takes nothing returns nothing
    set gg_trg_cwfec = CreateTrigger(  )
    call TriggerAddAction( gg_trg_cwfec, function Trig_cwfec_Actions )
endfunction
03-25-2004, 11:30 PM#5
dataangel
The problem is with GetHandleHandle in the second part. You need to make a return bug function that converts handles to units. Annoying, I know, but necessary :/
03-26-2004, 03:19 AM#6
weaaddar
for some reason blizzard compiler finds such behavior exceptable so its not as annoying as return bug ussually is.
function H2U takes handle h returns unit
return h
endfunction
03-26-2004, 07:12 AM#7
jardragon901
Thank you so much guys it works perfectly.
Another thing, since I'm using a local trigger should I destroy it after use?
03-26-2004, 01:38 PM#8
KaTTaNa
You definately should. The easiest would be to add DestroyTrigger(GetTriggeringTrigger()) at the end of the function Trig_cwfec_Actions (to make sure have accessed the local variables before it gets destroyed).
creating triggers ingame problem - Wc3C.net