• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] need help with a trigger

Status
Not open for further replies.
Level 4
Joined
Mar 23, 2009
Messages
78
Hi everyone. Here's the code of trigger's Actions function:
JASS:
    local integer i=0
    local location loc
    local unit u=GetSpellAbilityUnit()
    set i=GetPlayerId(GetOwningPlayer(u))
    call DisplayTextToPlayer(Player(i),0,0,I2S(GetUnitTypeId(u)))
    if RectContainsCoords(udg_INV_LOCS[i], GetUnitX(u), GetUnitY(u)) then
        //Moves unit not to the udg_inv_TP[i] but to (0; 0)
        call SetUnitX(u,GetLocationX(udg_inv_TP[i]))
        call SetUnitY(u,GetLocationY(udg_inv_TP[i]))
    else
        set loc=Location(GetUnitX(u),GetUnitY(u))
        set udg_inv_TP[i]=loc
        call SetUnitX(u,GetRectCenterX(udg_INV_LOCS[i]))
        call SetUnitY(u,GetRectCenterY(udg_INV_LOCS[i]))
    endif
    call PanCameraToTimedForPlayer(GetOwningPlayer(u),GetUnitX(u),GetUnitY(u),0.)
    call RemoveLocation(loc)
    set loc=null
    set u=null
I tried to use GetUnitLoc() instead of Location() but the result is the same. How this can be fixed?
 
Level 15
Joined
Feb 15, 2006
Messages
851
Hmmm, you don't' need the locations for anything, just use directly GetUnitX/Y.

JASS:
local integer i=0
//local location loc
local unit u=GetSpellAbilityUnit()
set i=GetPlayerId(GetOwningPlayer(u))
call DisplayTextToPlayer(Player(i),0,0,I2S(GetUnitTypeId(u)))
if RectContainsCoords(udg_INV_LOCS[i], GetUnitX(u), GetUnitY(u)) then
    //Moves unit not to the udg_inv_TP[i] but to (0; 0)
    call SetUnitX(u,GetLocationX(udg_inv_TP[i])) // that means udg_inv_TP[i] has not been defined, it's null
    call SetUnitY(u,GetLocationY(udg_inv_TP[i]))
else
    set loc=Location(GetUnitX(u),GetUnitY(u))
    set udg_inv_TP[i]=loc
    call SetUnitX(u,GetRectCenterX(udg_INV_LOCS[i]))
    call SetUnitY(u,GetRectCenterY(udg_INV_LOCS[i]))
endif
call PanCameraToTimedForPlayer(GetOwningPlayer(u),GetUnitX(u),GetUnitY(u),0.)
call RemoveLocation(loc)
set loc=null
set u=null
What's the purpose of this code??

For more support in jass, visit www.wc3jass.com
 
Level 4
Joined
Mar 23, 2009
Messages
78
it moves a hero to the location where his chest is located, and returns him back to the point where he casted spell.
udg_inv_TP cannot be null, as the first cast is surely not from the rect udg_INV_LOCS.
 
Level 4
Joined
Mar 23, 2009
Messages
78
that's strange, but this
JASS:
local unit u=GetSpellAbilityUnit()
set i=GetPlayerId(GetOwningPlayer(u))
...
leaves a leak, while this doesnt
JASS:
local unit u=GetSpellAbilityUnit()
set i=GetPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
...
 
It's not working because you remove the location. Remember that variables are pointers, not representative of the actual object. So if you set the global to loc, you aren't copying the data, you are just making them both point to the same object in memory. Therefore, if you remove the location that loc points to, then that means you are also removing the location that the global points to. (because they are pointing to the same object)

Here is how the code should look:
JASS:
local unit u = GetSpellAbilityUnit()
local integer i = GetPlayerId(GetOwningPlayer(u)) 
call DisplayTextToPlayer(Player(i),0,0,I2S(GetUnitTypeId(u)))
if RectContainsCoords(udg_INV_LOCS[i], GetUnitX(u), GetUnitY(u)) then
    //Moves unit not to the udg_inv_TP[i] but to (0; 0)
    call SetUnitX(u,GetLocationX(udg_inv_TP[i]))
    call SetUnitY(u,GetLocationY(udg_inv_TP[i]))
    call RemoveLocation(udg_inv_TP[i]) // clear the leak later on
else
    set udg_inv_TP[i]=GetUnitLoc(u)
    call SetUnitX(u,GetRectCenterX(udg_INV_LOCS[i]))
    call SetUnitY(u,GetRectCenterY(udg_INV_LOCS[i]))
endif
call PanCameraToTimedForPlayer(GetOwningPlayer(u),GetUnitX(u),GetUnitY(u),0.)
set u=null
 
Status
Not open for further replies.
Top