HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How is this triggering?

08-11-2007, 09:06 AM#1
Dil999
I've just started to learn about timers and gamecaches with JASS. I worked alot in the past few hours to complete this knockback function. It allows you to change the speed, duration, effects attached to the unit, and the effects that are created on the ground as the unit goes. Thanks to alot of help from the War Stomp tutorial, I finished it.
My question is, is there anything which is leaking or can be optimized/I'm doing wrong that can be changed to make my coding better.

Collapse JASS:
function I2U takes integer i returns unit
    return i
    return null
endfunction

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function H2U takes handle h returns unit
    return h
    return null
endfunction

function I2H takes integer i returns handle
    return i
    return null
endfunction

function E2H takes effect e returns handle
    return e
    return null
endfunction

function H2E takes handle h returns effect
    return h
    return null
endfunction
    


function Knockback_Move takes nothing returns nothing
    local string s = I2S(H2I(GetExpiredTimer()))
    local gamecache gc = udg_Cache
    local unit u = H2U(I2H(GetStoredInteger(gc,s,"unit")))
    local real angle = GetStoredReal(gc,s,"angle")
    local real dur = GetStoredReal(gc,s,"dur")
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real speed = GetStoredReal(gc,s,"speed")
    local real x2 = x + speed * Cos(angle * bj_DEGTORAD)
    local real y2 = y + speed * Sin(angle * bj_DEGTORAD)
    local integer dust = GetStoredInteger(gc,s,"dust")
    set dust = dust + 1
    set speed = speed - (dur * dur * dur)
    
    if dust >= 4 then
        set dust = 0
        call DestroyEffect(AddSpecialEffect(GetStoredString(gc,s,"groundeffect"),x2,y2))
    endif
    call FlushStoredInteger(gc,s,"dust")
    call StoreInteger(gc,s,"dust",dust)
    call FlushStoredReal(gc,s,"speed")
    call StoreReal(gc,s,"speed",speed)
    set dur = dur + 0.05
    call FlushStoredReal(gc,s,"dur")
    call StoreReal(gc,s,"dur",dur)
    set dur = dur + 0.05
        if dur >= 1.50 then
            call PauseTimer(GetExpiredTimer())
            call DestroyTimer(GetExpiredTimer())
            call DestroyEffect(H2E(I2H(GetStoredInteger(gc,s,"effect"))))
        endif
    call SetUnitPosition(u,x2,y2)
    

    
    set gc = null
    set s = null
    set u = null    
endfunction

function KnockbackUnit takes unit Caster, unit Target, real Speed, real Duration, string AttachedEffect,string EffectAttachmentPoint,string GroundEffect returns nothing
    local timer t = CreateTimer()
    local gamecache gc = udg_Cache
    local string s = I2S(H2I(t))
    local unit u = Caster
    local unit u2 = Target
    local real dur = Duration
    local real angle = bj_RADTODEG * Atan2(GetUnitY(u2) - GetUnitY(u),GetUnitX(u2) - GetUnitX(u))
    local real speed = Speed
    local effect e = AddSpecialEffectTarget(AttachedEffect,u2,EffectAttachmentPoint)
    call StoreString(gc,s,"groundeffect",GroundEffect)
    call StoreInteger(gc,s,"effect",H2I(E2H(e)))
    call StoreInteger(gc,s,"dust",0)
    call StoreReal(gc,s,"speed",speed)
    call StoreReal(gc,s,"angle",angle)
    call StoreInteger(gc,s,"unit",H2I(u2))
    call StoreReal(gc,s,"dur",0.0)
    call TimerStart(t,0.05,true,function Knockback_Move)
    
    set gc = null
    set s = null
    set u = null
    set u2 = null
    set t = null
    set e = null
endfunction
08-11-2007, 09:35 AM#2
Toink
Don't use I2U or I2H, I've heard it can cause some errors or the likes.

And for the record, effects and units are already handles.
type unit extends handle type effect extends handle
So No need to use E2H

Oh and take my advice, as soon as you learn about vJass and how to use scopes, you should use them as much as possible. If you will be coding some spells, use a scope and make things private globals to make it faster than gamecache unless you want it to be MUI. In that case use structs.
08-11-2007, 02:12 PM#3
Earth-Fury
Actually, toink, unit extend widget. Item and destructable do too. (objects with life that can die)
And functions that take a sub-type of something else only take that sub-type and sub-types of it. Thus why H2I() is all you need, but you still need I2U() ext.

And Dill, look in to vJASS and grims data system. Gamecache using I2H() functions can become buggy, with bugs that can't easily (or at all) be fixed. (we never should have been using I2H() in the first place, but there wasn't much of an alternative in the past. now there is.)

http://wc3campaigns.net/pastebint.ph...3ffd04408ae7e1
Data System

http://wc3campaigns.net/showthread.php?t=90999
Jass New Gen (includes JASSHelper, the vJASS preprossesor)
08-11-2007, 07:12 PM#4
Dil999
Thanks for the help. I already have Jass New Gen (d3, right?) but ill make sure t o check out that data system. I'm having friends who dont play wc over for a week, so I wont have much time to change my code, but when I'm back I'll make all those changes.
08-12-2007, 08:54 AM#5
Beardo
2 words: use structs
08-12-2007, 09:05 AM#6
Earth-Fury
Quote:
Originally Posted by Beardo
2 words: use structs
thats not helpfull. "use structs"...
#1: Structs alone are not a replacement for handle vars
#2: Stating "use ____" with nothing else is just useless.

And I alredy said that, only more exaustivly. So why the hell are you posting?
08-12-2007, 09:09 AM#7
Beardo
was going to edit the post. got side tracked and forgot to do it

I know they're not a replacement. I never said that

I was under the impression that using a single struct instead of attaching 7 different things to a timer would be alot more efficent. not to mention the problems with I2H