• 🏆 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] using region as rect

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
How do i use region as a rect?
JASS:
    function X takes unit u, real t, integer p, region r returns nothing
    local rect DRect = Rect(0, 0, 0, 0)
        if ST[1] >= 1 then
            call SetUnitFlyHeight(u, 0, GetUnitFlyHeight(u) / t)
            call MoveRectToLoc(DRect, GetRegionCenter(r))
            call SetUnitPositionLoc(u, GetRectCenter(DRect))
            set ST[1] = ST[1] - 1
        endif
    endfunction

how do i use region as the rect?

Btw: GetRegionCenter() dont exist, thats why i need help.

***************nevermind, found another solution.**************
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Region and rect is the same thing.

Edit -

Regions in GUI = Regions in World Editor = Rects in JASS

Regions in GUI and World Editor != not equal to Regions in JASS
 
Last edited:
Level 13
Joined
May 11, 2008
Messages
1,198
hmm...18 functions in function display in jngp for regions but i don't know what they're for...never used them.

i used to use regions in gui but now i sometimes but rarely use rects in jass. idk what a region is in jass. it looks like same thing as rect but idk...

if you make a region and make a trigger that can select that region, then convert that trigger to custom text...then look for the gg variable name.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Regions are more-or-less a collection of rects. Natives such as TriggerRegisterEnterRegion do not have an equivalent rect-specific counterpart and as such you need to use RegionAddRect. Regions do not have to be any particular shape, by adding various points throughout the map you could for instance setup a region that is triangular, for example.

To answer your question more directly, if you're trying to replicate a region to occupy the exact same space as a rect then use RegionAddRect(yourRegion, yourRect), but remember that you'll need to initialize the region with CreateRegion before you can use it. The constructor for rect handles is Rect, followed by 4 values that define its properties.

JASS:
globals
    private region returnResult
endglobals

function CreateRectRegion takes rect r returns region
    set returnResult = CreateRegion()
    call RegionAddRect(returnResult, r)
    return returnResult
endfunction

Also worth mentioning is that if you destroy a rect that was added to a region it will not actually affect the region in any way, it will still occupy the same area.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Yes, I believe so.

I used this script to test it, it's fairly simple but it shows how it works in a very non-visual way.

JASS:
scope RegionTest initializer init


//* 
//* When a unit enters the the "test" region (which is composed of two 
//* unadjacent rects) a message will be displayed to the user giving
//* the name of the triggering unit.
//*
//* If the message is displayed twice while the unit runs in a straight
//* line, it shows that the region is in two separate places at once.
//*
private function onDetectEnter takes nothing returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 4, GetUnitName(GetTriggerUnit())+" has entered the test region.")

endfunction


public function init takes nothing returns nothing
    local rect array rct
    local region test = CreateRegion()
    local trigger detect = CreateTrigger()
    
        set rct[0] = Rect(-400, -400, -100, 400)
        set rct[1] = Rect(100, -400, 400, 0)
        
        call RegionAddRect(test, rct[0])
        call RegionAddRect(test, rct[1])
        
        call TriggerRegisterEnterRegion(detect, test, null)
        call TriggerAddAction(detect, function onDetectEnter)

endfunction


endscope
 
Status
Not open for further replies.
Top