HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Jass effect for time

05-13-2006, 11:35 PM#1
The)TideHunter(
Heya guys, just a question, i wrote some code up and was wondering if this is a officient way to create a effect on a widget for time.
I dont actually know if this will give any errors either, because my jass editing program is going abit crazy atm.

Collapse JASS:
// Globals (Only used for Jass Editing Programs)
globals
    gamecache udg_GC = null
endglobals

// Game Cache Return
function GC takes nothing returns gamecache
    if(udg_GC == null) then
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

// Handle Variables
function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Effect takes integer I returns effect
    return I
    return null
endfunction

// Well Used Functions

//**********
// function: CreateEffectOnWidget(widget whichWidget, string attachPoint, string effectFilePath, real dur)
//
function CreateEffectOnWidget_Destroy takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local effect e = I2Effect(GetStoredInteger(GC(), I2S(H2I(t)), "CreateEffectOnWidgetEffect"))
    call DestroyEffect(e)
    set t = null
    set e = null
endfunction

function CreateEffectOnWidget_Create takes widget whichWidget, string attachPoint, string effectFilePath, real dur returns nothing
    local effect e = AddSpecialEffectTarget(effectFilePath, whichWidget, attachPoint)
    local timer t = CreateTimer()
    call StoreInteger(GC(), I2S(H2I(t)), "CreateEffectOnWidgetEffect", I2S(H2I(e)))
    call TimerStart(t, dur, false, function CreateEffectOnWidget_Destroy)
endfunction

//**********
05-13-2006, 11:43 PM#2
Vexorian
Add
call FlushGameCache(InitGameCache("GC"))

before calling assigning to the variable, if you are planning to use this in single player, also set effect and timer to null in the _Create function
05-13-2006, 11:46 PM#3
The)TideHunter(
Thx vex i'l add the Flush.
So theres no errors?

EDIT: is it possible to StartTime, with a create timer function like this:

Collapse JASS:
function CreateEffectOnWidget_Create takes widget whichWidget, string attachPoint, string effectFilePath, real dur returns nothing
    local effect e = AddSpecialEffectTarget(effectFilePath, whichWidget, attachPoint)
    call StoreInteger(GC(), I2S(H2I(t)), "CreateEffectOnWidgetEffect", I2S(H2I(e)))
    call TimerStart(CreateTimer(), dur, false, function CreateEffectOnWidget_Destroy)
endfunction

Or does the timer have to already exsist?
05-13-2006, 11:53 PM#4
Vexorian
The timer will exist.

An object does not need to be pointed by a variable to exist.

In fact, that's the reason we have memory leaks.

I do TimerStart(CreateTimer(),... as much as possible.

But in your case you need to save the timer in a variable in order to use I2S(H2I(t))
05-13-2006, 11:58 PM#5
The)TideHunter(
Ah yes, good spotting, dident see i used it just then in the StoreInt function.
Thanks again vex :)