• 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.

[Solved] Create Region at Unit

Status
Not open for further replies.
Level 4
Joined
Dec 13, 2010
Messages
71
JASS:
function CreateRegionAtHouse takes unit House returns region
    local location TempPoint = GetUnitLoc(House)
    local location TempPointX = Location((GetLocationX(TempPoint)-185),(GetLocationY(TempPoint)-185))
    local location TempPointY = Location((GetLocationX(TempPoint)+185),(GetLocationY(TempPoint)+185))
    local rect TempRect = RectFromLoc( TempPointX, TempPointY)
    local region TempRegion = CreateRegion()
    set TempRegion = RegionAddRect(TempRegion, TempRect)
    return TempRegion
endfunction

So I want to create a 370*370 Region at the House

My problem is: set TempRegion=RegionAddRect(TempRegion, TempRect)
Error: Cannot convert nothing to region
 
Last edited by a moderator:
you do know the whole point of locals is to shorten the names and make it faster and easier right ?

Don't use locations when using jass.
do it like this.

JASS:
function CreateRegionAtHouse takes unit u returns region
    local real x = GetUnitX( u)
    local real y = GetUnitY( u)
    local rect rct = Rect( x - 185, y - 185, x + 185, y + 185)
    local region r = CreateRegion()
    call RegionAddRect( r, rct)
    set rct = null
    // problem is when returning like this the local region always leaks.
    return r
endfunction

so do it like this to prevent leaks.
create a region in the trigger you call this function from.

JASS:
function CreateRegionAtHouse takes unit u, region r returns region
    local real x = GetUnitX( u)
    local real y = GetUnitY( u)
    local rect rct = Rect( x - 185, y - 185, x + 185, y + 185)
    call RegionAddRect( r, rct)
    set rct = null
    // now it doesn't leak the region
    return r
endfunction

Also note that regions are created by multiples of 32. so creating a region that isn't a division of 32 can cause unwanted results.

Also this is not vJass
 
Just use:
JASS:
call RegionAddRect(TempRegion, TempRect)
The function itself will add the rect to "TempRegion". You don't have to assign it again. Remember that variables are just pointers.

EDIT: Death posted before me.
you do know the whole point of locals is to shorten the names and make it faster and easier right ?
It is okay to have longer names. It is nice for explicitness. In the end, it is up to the user.
 
Status
Not open for further replies.
Top