HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Stupid Bug - Null Timer

03-13-2006, 03:28 PM#1
Chuckle_Brother
I was trying to make a utility function that I would be using for my entry to the Spell Making Session 02. Just a simple function to fade out a unit over time. It seems to work and all, but the timeout timer that dictates when it should stop the recursive timer that does the actual is being thought to be null, and the ClearTimer function I use(cause I'm lazy) is complaining about it being null.

if anyone sees an error in the code please tell me.

Collapse JASS:
function MakeUnitFade takes unit target, real finaltransparency, real inittransparency, real duration returns nothing
    local timer timed=CreateTimer()
    local string timeds=GetAttachmentTable(timed)
    local timer end=CreateTimer()
    local string ends=GetAttachmentTable(end)
    local real fadeout=((finaltransparency - inittransparency) / duration) / 25
    //Set the stuff for the fadeout
    call SetTableObject(timeds, "target", target)
    call SetTableReal(timeds, "currentfade", inittransparency)
    call SetTableReal(timeds, "fadeout", fadeout)
    //Set the stuff to the ending timer
    call SetTableObject(ends, "timer", timed)
    call DisplayTimedTextToForce( GetPlayersAll(), 3.00, "Periodic timer added to the table: " + ends )
    //Start up the fadeout timer
    call TimerStart(timed, 0.04, true, function MadeUnitFade_Child)
    call TimerStart(end, duration, false, function MakeUnitFade_End)
    call MakeUnitFade_End()
    set timed=null
    set end=null
endfunction

Collapse JASS:
function MakeUnitFade_End takes nothing returns nothing
    local timer end=GetExpiredTimer()
    local string ends=GetAttachmentTable(end)
    local timer timed=GetTableTimer(ends, "timer")
    call ClearTimer(timed)
    call ClearTimer(end)
    call DisplayTimedTextToForce( GetPlayersAll(), 3.00, "Fadeout Ended")
    set end=null
    set timed=null
endfunction

Collapse JASS:
function MadeUnitFade_Child takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local string s=GetAttachmentTable(t)
    local unit u=GetTableUnit(s, "target")
    local real cfade=GetTableReal(s, "currentfade")
    local real fadeout=GetTableReal(s, "fadeout")
    set cfade= (cfade + fadeout)
    //call DisplayTimedTextToForce( GetPlayersAll(), 3.00, "fading" )
    call SetUnitVertexColor(u, 255, 255, 255, PercentTo255(100.0-cfade))
    call SetTableReal(s, "currentfade", cfade)
    set t=null
    set u=null
endfunction

Oh and the messages are debug messages I use that will not be present in the final cut.
03-13-2006, 04:25 PM#2
emjlr3
i havent read yet, but check my Quake abiltiy for a fade thing, it may help, ill edit my post once ive read your scripting

yea i dont really know Tables yet, I still use Handle Vars so I cant be much help here, anywho, check my quake it may help
03-13-2006, 04:31 PM#3
Chuckle_Brother
I understand the principles of fading a unit out. The timer just is being read as null...and I have no clue why.

FYI, tables aren't much different than handles, the only real difference is that when you attach something through handles you go:
SetHandleTYPE(OBJECT, TAG, VALUE)

while in tables you use:
SetTableTYPE(STRING, TAG, VALUE), with the string being converted from H2I then I2S previously, so you don't rely on H2I as much.