HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Hey, um Destroy Trigger Actions SUCKS ASS.

07-04-2004, 02:35 PM#1
weaaddar
While working on Vex's recent challenge I came upon an epiphany...
Getting Rid of tas is probably the most annoying challenge I came upon. My solution relies heavily on the wonderful timer. But I don't know if this looks good to you guys, maybe you have a better solution.
Code:
function CleanUp takes nothing returns nothing
	local gamecache itt=InitGameCache("items.w3v")
	local timer t=GetExpiredTimer()
	local string this=I2S(H2I(t))
	local trigger trig=I2T(GetStoredInteger(itt,this,"t"))
	local triggeraction ta=I2TA(GetStoredInteger(itt,this,"ta"))
	call TriggerRemoveAction(trig,ta)
	call DestroyTrigger(trig)
	call DestroyTimer(t)
	call FlushStoredMission(itt,this)
	set itt=null
	set trig=null
	set ta=null
endfunction

function Trig_init_Actions takes nothing returns nothing
    local gamecache itt=InitGameCache("items.w3v")
    local timer t=CreateTimer()
    local string this=I2S(H2I(t))
    call EnumItemsInRectBJ( GetPlayableMapRect(), function Add_item_to_Cache )
    call StoreInteger(itt,this,"t",H2I(GetTriggeringTrigger()) )
    call StoreInteger(itt,this,"ta",H2I(gg_trg_init_items))
    call TimerStart(t,0,false,function CleanUp)
    set itt=null
    set t=null
endfunction

//===========================================================================
function InitTrig_init_items takes nothing returns nothing
    local trigger t=CreateTrigger(  )
    local integer i=H2I( TriggerAddAction( t, function Trig_init_Actions ))
     call TriggerRegisterTimerEventSingle( t, 0.00 )   
    set gg_trg_init_items=I2T(i)
endfunction

You see, you can't store stuff to cache during map init, thats why I save the Triggeraction to the global variable given to me by this trigger.
I use a timer to allow me to destroy the TriggerAction and the Trigger, as destroying the TriggerAction means the thread dies if its running from
that trigger, and if I destroy the Trigger it means the trigger action leaks. But If I use a tiemr I can spare either of them from leaking. Kill the timer
and set em all to null. meaning I win. This process also sucks. Any better suggestions?
07-04-2004, 09:49 PM#2
Vexorian
I found destroying triggeractions so difficult that I decided to forget about that. I rarely do that.