HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why doesn't it work

06-27-2006, 08:36 PM#1
StockBreak
This code doesn't work because the necromancer it's not ALWAYS surrounded by the Blight, sometimes it disappears then reappears. Could you help? Thanks. Here's the code:
Collapse JASS:
//===========================================================================
// Blight
//===========================================================================
function RemoveBlight takes nothing returns nothing
    local trigger trig = GetTriggeringTrigger(  )
    local location loc = I2Loc( GetStoredInteger( udg_gameCache, "RemoveBlight", I2S( H2I( trig ) ) ) )
    local unit u = I2U( GetStoredInteger( udg_gameCache, "RemoveBlight", I2S( H2I( trig ) + 1 ) ) )
    local location unitLoc = GetUnitLoc( u )
    local real distance = DistanceBetweenPoints( loc, unitLoc )

    call DisplayTextToForce( GetPlayersAll(  ), R2S( distance ) )
    // if ( not( IsUnitInRangeLoc( u, loc, 400 ) ) ) then
    if distance > 400 then
        call SetBlightLoc( Player( 0 ), loc, 200, false )
        call RemoveLocation( loc )
        call DestroyTrigger( GetTriggeringTrigger(  ) )
    endif

    set trig = null
    set u = null
    set loc = null
    call RemoveLocation( unitLoc )
    set unitLoc = null
endfunction

//===========================================================================
function Trig_Blight_Actions takes nothing returns nothing
    local unit u = udg_necromancer
    local location loc = GetUnitLoc( u )
    local trigger trig = CreateTrigger(  )

    call SetBlightLoc( GetOwningPlayer( u ), loc, 200, true )
    call StoreInteger( udg_gameCache, "RemoveBlight", I2S( H2I( trig ) ), H2I( loc ) )
    call StoreInteger( udg_gameCache, "RemoveBlight", I2S( H2I( trig ) + 1 ), H2I( u ) )
    call TriggerRegisterTimerEventPeriodic( trig, 6 )
    call TriggerAddAction( trig, function RemoveBlight )

    set u = null
    set loc = null
    set trig = null
endfunction

//===========================================================================
function InitTrig_Blight takes nothing returns nothing
    set gg_trg_Blight = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Blight, 1.0 )
    call TriggerAddAction( gg_trg_Blight, function Trig_Blight_Actions )
endfunction

06-27-2006, 08:47 PM#2
Captain Griffen
Don't know, but that code is very inefficient. Why are you using locations at all? X and Y co-ordinates are so much easier, and using them would reduce the usage of H2I and I2Loc, which are very slow. DistanceBetweenPoints is a BJ, as well.

When you put in a debug message, could you please tell us what the debug output is...? Only that would be most helpful.

Why:

H2I( trig ) + 1

? This means that it is no longer unique. Use I2S(H2I(trig)) + "1"
06-27-2006, 09:16 PM#3
PipeDream
Not only is it not unique but the next time the timer fires you're immediately stepping on your own toes. Attached var style strongly recommended:
call StoreInteger(GC(),I2S(HtoI(thingtoattachto)),"nameofattachment",attachedvar)
06-27-2006, 10:12 PM#4
Vexorian
Quote:
? This means that it is no longer unique. Use I2S(H2I(trig)) + "1"
That could fail as well sometimes , instead use I2S(H2I(trig)) + ";1"
06-27-2006, 10:20 PM#5
PipeDream
Yes if you're making 100,000 triggers.. although with lightning it would happen right away.
06-28-2006, 11:58 AM#6
StockBreak
Quote:
Originally Posted by Captain Griffen
When you put in a debug message, could you please tell us what the debug output is...? Only that would be most helpful.

Why:

H2I( trig ) + 1

? This means that it is no longer unique. Use I2S(H2I(trig)) + "1"
The debug message only shows the distance between the 2 points, thanks for your hint!

Quote:
Originally Posted by PipeDream
the next time the timer fires you're immediately stepping on your own toes.
What do you mean? Thanks

Quote:
Originally Posted by Vexorian
That could fail as well sometimes , instead use I2S(H2I(trig)) + ";1"
Thanks.
06-28-2006, 01:57 PM#7
PipeDream
There's a heap of handles which are distributed whenever you create something. Unless they've been mixed up out of order by allocating/freeing randomly they come one after the other. So, once you RemoveLocation(), you've decremented to where the next CreateTrigger() will overlap with the previous stuff in the game cache. E.g., first handle is usually 0x1005C, next one is 0x1005D, which is just 0x1005C+1.
Or it will happen randomly if lots of other creation/destruction is going on.
06-28-2006, 03:35 PM#8
StockBreak
Here is the new code (I hope it's leaks free) but, if you test it, it doesn't still work! The problem is that the blight is deleted also under the necromancer, any suggestion? Thanks:
Collapse JASS:
//===========================================================================
// Creates a blighted field around a necromancer every 1 second
//===========================================================================

function RemoveBlight takes nothing returns nothing
    local trigger trig = GetTriggeringTrigger(  )
    local unit necro = I2U( GetStoredInteger( udg_gameCache, I2S( H2I( trig ) ) + "necro", "RemoveBlight") )
    local real necroX = GetUnitX( necro )
    local real necroY = GetUnitY( necro )
    local real oldX = GetStoredReal( udg_gameCache, I2S( H2I( trig ) ) + "X", "RemoveBlight")
    local real oldY = GetStoredReal( udg_gameCache, I2S( H2I( trig ) ) + "Y", "RemoveBlight")
    local real distance = SquareRoot(necroX * necroX + oldX * oldY)

    // DEBUG
    call DisplayTextToForce( GetPlayersAll(  ), "*** DEBUG ***" )
    call DisplayTextToForce( GetPlayersAll(  ), "New Necro's X: " + R2S( oldX ) )
    call DisplayTextToForce( GetPlayersAll(  ), "New Necro's Y: " + R2S( oldY ) )

    if distance > 600 then
        call SetBlight( Player( 0 ), oldX, oldY, 200, false )
        call DestroyTrigger( GetTriggeringTrigger(  ) )
    endif

    set trig = null
    set necro = null
endfunction

//===========================================================================
function Trig_Blight_Actions takes nothing returns nothing
    local unit necro = udg_necromancer
    local real necroX = GetUnitX( necro )
    local real necroY = GetUnitY( necro )
    local trigger trig = CreateTrigger(  )

    // DEBUG
    call DisplayTextToForce( GetPlayersAll(  ), "Necro's X: " + R2S( necroX ) )
    call DisplayTextToForce( GetPlayersAll(  ), "Necro's Y: " + R2S( necroY ) )

    call SetBlight( Player( 0 ), necroX, necroY, 200, true )
    call StoreReal( udg_gameCache, I2S( H2I( trig ) ) + "X", "RemoveBlight", necroX )
    call StoreReal( udg_gameCache, I2S( H2I( trig ) ) + "Y", "RemoveBlight", necroY )
    call StoreInteger( udg_gameCache, I2S( H2I( trig ) ) + "necro", "RemoveBlight", H2I( necro ) )
    call TriggerRegisterTimerEventPeriodic( trig, 5.0 )
    call TriggerAddAction( trig, function RemoveBlight )

    set necro = null
    set trig = null
endfunction

//===========================================================================
function InitTrig_Blight takes nothing returns nothing
    set gg_trg_Blight = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Blight, 1.0 )
    call TriggerAddAction( gg_trg_Blight, function Trig_Blight_Actions )
endfunction