• 🏆 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!

[Solved] Create Region at Unit

Status
Not open for further replies.
Level 4
Joined
Dec 13, 2010
Messages
70
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:
Level 29
Joined
Oct 24, 2012
Messages
6,543
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