• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Moved to Center of the map???

Status
Not open for further replies.
Level 7
Joined
Mar 22, 2010
Messages
228
JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_VillHouse_In_Actions takes nothing returns nothing
    local real x
    local real y
    local rect r
    local rect all
    set r = gg_rct_Village_House_In
    set x = GetRectCenterX(r)
    set y = GetRectCenterY(r)
    call SetUnitPosition( GetTriggerUnit(), x, y + 90 )
    call RemoveRect(r)
    set r = gg_rct_Village_House_V
    set all = GetPlayableMapRect()
    call CreateFogModifierRectBJ(false, GetOwningPlayer(GetTriggerUnit()), FOG_OF_WAR_VISIBLE, all)
    call CreateFogModifierRectBJ(true, GetOwningPlayer(GetTriggerUnit()), FOG_OF_WAR_VISIBLE, r)
    call PanCameraToTimedForPlayer(GetOwningPlayer(GetTriggerUnit()), x, y + 90, 0)
    call RemoveRect(r)
    call RemoveRect(all)
endfunction

//===========================================================================
function InitTrig_VillHouse takes nothing returns nothing
    set gg_trg_VillHouse = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_VillHouse, gg_rct_Village_House )
    call TriggerAddAction( gg_trg_VillHouse, function Trig_VillHouse_In_Actions )
endfunction

i havent missed any of it i guess, but when i try to do it for the 3rd time, i will move my unit to the center of the map!!!please HELP!
 
You are removing the rect that you are using. So the center X/Y returns null (0).

Think of it this way, the local variable "r" just acts as a pointer. It "points" to the rect.

When you remove the rect "r", you are removing the rect entirely. You aren't just removing the variable. Since gg_rct_Village_House_In references to that same rect, a problem arises. When you remove the rect, gg_rct_Village_House_In is now pointing to a rect that does not exist. So the next time it executes the trigger, it will set it to that global, which represents a rect that doesn't exist. When you try to get the X/Y of a rect that doesn't exist, it returns 0.

All-in-all, basically just don't remove the rect. (Just remove that line) It isn't a "leak" as long as you are using that variable for the duration of the entire map.

You can use CodeMonkey's idea as well as long as that rect never moves. You can also view the center X/Y by right-clicking the region and selecting "Rename". Then it will tell you its properties.
 
Level 7
Joined
Mar 22, 2010
Messages
228
ok for an instance,.if the function takes(needs) a region,. what local variable am i gonna use?.i cant use x and y for visibility..like
JASS:
    call CreateFogModifierRectBJ(true, GetOwningPlayer(GetTriggerUnit()), FOG_OF_WAR_VISIBLE, -->region<--)
can i convert location to region?
or ...does memory leak exist when i dont remove the region?
im thinking of this memory leak.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
JASS:
function Trig_VillHouse_In_Conditions takes nothing returns boolean
    local real x = GetRectCenterX(gg_rct_Village_House_In)
    local real y = GetRectCenterY(gg_rct_Village_House_In)
    local player p = GetOwningPlayer(GetTriggerUnit())
 
    call SetUnitPosition(GetTriggerUnit(),x,y + 90.)
    call FogModifierStart(CreateFogModifierRect(p,FOG_OF_WAR_VISIBLE,gg_rct_Village_House_V,true,false))
    call PanCameraToTimedForPlayer(p,x,y + 90,0.)
 
//This will reveal the whole map... are you sure?
//  call CreateFogModifierRectBJ(false,p,FOG_OF_WAR_VISIBLE,bj_mapInitialPlayableArea)
 
    return false
endfunction
 
//===========================================================================
function InitTrig_VillHouse takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,gg_rct_Village_House)
    call TriggerAddCondition(t,function Trig_VillHouse_In_Conditions)
endfunction

You shouldn't be removing any of those regions, unless you only plan to use them once.
 
Status
Not open for further replies.
Top