• 🏆 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] Global Rect Declaration Help

Status
Not open for further replies.
Level 4
Joined
Sep 24, 2004
Messages
49
JASS:
scope pZONE initializer init
globals
    private constant rect PORTALA   =   gg_rct_ENTRY_ZONE
    private constant rect PORTALB   =   gg_rct_EXIT_ZONE
endglobals

private function Conditions takes nothing returns boolean  
    return true
    //return GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_USER 
endfunction

private function ActionsA takes nothing returns nothing
    local location l = Location(GetRectCenterX(PORTALB), GetRectCenterY(PORTALB))
    call SetUnitPositionLoc(GetEnteringUnit(), l)
    call RemoveLocation(l)
endfunction

private function ActionsB takes nothing returns nothing
    local location l = Location(GetRectCenterX(PORTALA), GetRectCenterY(PORTALA))
    call SetUnitPositionLoc(GetEnteringUnit(), l)
    call RemoveLocation(l)
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger tA = CreateTrigger(  )
    local trigger tB = CreateTrigger(  )
    local region rectRegionA = CreateRegion()
    local region rectRegionB = CreateRegion()
    call RegionAddRect(rectRegionA, PORTALA)
    call TriggerRegisterEnterRegion(tA, rectRegionA, null)
    call TriggerAddCondition( tA, Condition( function Conditions ) )
    call TriggerAddAction( tA, function ActionsA)
    //call RemoveRegion(rectRegionA)
    
    call RegionAddRect(rectRegionB, PORTALB)
    call TriggerRegisterEnterRegion(tB, rectRegionB, null)
    call TriggerAddCondition( tB, Condition( function Conditions ) )
    call TriggerAddAction( tB, function ActionsB)
    //call RemoveRegion(rectRegionB)
    
    set tA = null
    set tB = null
endfunction
endscope
When running the trigger: A unit enters the region - nothing happens. Is it not possible to declare constant rects in this way, or is it something else?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
It's not possible to do it like that, but you can simply do this:

JASS:
globals
    private rect PORTALA
    private rect PORTALB
endglobals

// ...

private function init takes nothing returns nothing
    // ...
    set PORTALA = gg_rct_ENTRY_ZONE
    set PORTALB = gg_rct_EXIT_ZONE
    // ...
endfunction

Custom globals are initialized before those gg_ ones. Also, you have to remove "constant", because otherwise it will stay uninitialized.
 
Level 4
Joined
Sep 24, 2004
Messages
49
Maybe you got infinite loops because of those SetUnitPositionLoc functions. You can perhaps try SetUnitX/SetUnitY? Because otherwise I think the trigger is being fired over and over again.
Naw - I fixed it, but thanks.
Scope contains a group.
JASS:
if not(IsUnitInGroup(GetEnteringUnit(), UNITSWARPING)) then
        call SetUnitPositionLoc(GetEnteringUnit(), l)
        call GroupAddUnit(UNITSWARPING, GetEnteringUnit())
    else
        call GroupRemoveUnit(UNITSWARPING, GetEnteringUnit())
    endif
 
Status
Not open for further replies.
Top