| 01-13-2009, 04:12 AM | #1 |
Well I don't know about you but I was getting fed up making four seperate functions and four timers to handle the common remove of 'temporary' objects. Then it hit me: widgets. I was like OMG WIDGETS LOLOL! So I made a function SetWidgetExpire. It's a long story, but it didin't work because there's no Remove/DestroyWidget :( So needless to say I was angry at blizzard for the oversight. But then it came to me in a dream! JASS://Expire Widget Types: //0: unit //1: destructible //2: lightning //3: effect //4: item function W2U takes widget w returns unit return w return null endfunction function W2D takes widget w returns destructable return w return null endfunction function W2L takes widget w returns lightning return w return null endfunction function W2E takes widget w returns effect return w return null endfunction function W2I takes widget w returns item return w return null endfunction struct ExpireWidget widget w real dur integer wt endstruct globals ExpireWidget array ExpiringWidgetArray integer ExpireWidgetCounter = 0 timer ExpireWidgetTimer = CreateTimer() endglobals function WidgetExpireHandler takes nothing returns nothing local ExpireWidget ew local integer I = 0 loop set ew = ExpiringWidgetArray[i] set ew.dur = ew.dur - .1 if(ew.dur <= 0)then if(ew.wt == 0)then call RemoveUnit(W2U(ew.w)) set ew.w = null elseif(ew.wt == 1)then call RemoveDestructable(W2D(ew.w)) set ew.w = null elseif(ew.wt == 2)then call DestroyLightning(W2L(ew.w)) set ew.w = null elseif(ew.wt == 3)then call DestroyEffect(W2E(ew.w)) set ew.w = null else call RemoveItem(W2I(ew.w)) set ew.w = null endif call ew.destroy() set ExpireWidgetCounter = ExpireWidgetCounter - 1 set ExpiringWidgetArray[i] = ExpiringWidgetArray[ExpireWidgetCounter] endif exitwhen(I == ExpireWidgetCounter) set I = I + 1 endloop if(ExpireWidgetCounter == 0)then call PauseTimer(ExpireWidgetTimer) endif endfunction function SetWidgetExpire takes widget w, real dur, integer wt returns nothing local ExpireWidget ew = ExpireWidget.create() set ew.w = w set ew.dur = dur set ew.wt = wt set ExpiringWidgetArray[ExpireWidgetCounter] = ew if(ExpireWidgetCounter == 0)then call TimerStart(ExpireWidgetTimer, .1, true, function WidgetExpireHandler) endif set ExpireWidgetCounter = ExpireWidgetCounter + 1 endfunction It works, the widget does expire. Besides the obvious fact that if you get the wrong integer to denote the type causing a thread crash or wc3 crash, it works. My question is, how reliable is this? I'm always suspect of return bugging, but I'm return bugging an integer handle to an integer handle, right? At any rate, can anyone tell me if this is going to be reliable? I'd hate to start a general implementation and have my script start exploding. [Note to self: Effect does not extend the widget type... Whoops :D.] |
| 01-13-2009, 04:14 AM | #2 |
What use would this be for? |
| 01-13-2009, 04:16 AM | #3 |
Observe: Code:
function Trig_DoodadAnimTest_Func002002 takes nothing returns nothing
local destructable d = GetEnumDestructable()
call SetDestructableAnimationSpeed(d, .1)
call SetDestructableAnimation(d, "death")
call QueueDestructableAnimation(d, "Birth")
call SetWidgetExpire(d, 6.00, 1)
endfunction
function Trig_DoodadAnimTest_Actions takes nothing returns nothing
call AddSpecialEffectLocBJ( GetRectCenter(gg_rct_destr), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
call EnumDestructablesInRectAll( gg_rct_destr, function Trig_DoodadAnimTest_Func002002 )
endfunction
//===========================================================================
function InitTrig_DoodadAnimTest takes nothing returns nothing
set gg_trg_DoodadAnimTest = CreateTrigger( )
call TriggerRegisterEnterRectSimple( gg_trg_DoodadAnimTest, gg_rct_Test )
call TriggerAddAction( gg_trg_DoodadAnimTest, function Trig_DoodadAnimTest_Actions )
endfunctionThis was what I designed it for. This and temporary projectiles that needed to be removed rather then expire. I wanted to avoid the use of creating multiple timer for each type. Unfortunantly effect doesn't extend widget... So it's not quite as useful as I wanted. Really it just saves space. |
| 01-13-2009, 06:32 AM | #4 |
WIDGETS WTF LOL??? This is HANDLEs |
| 01-13-2009, 06:56 AM | #5 |
from common.j:type widget extends handle // an interactive game object with life type unit extends widget // a single unit reference type destructable extends widget type item extends widget |
