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

Rect how the funk?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Trying this again today but alas I just can't seem to get my rect/regions in order...

I want to search the grids around the green building for destructables. In the Image provided the ones marked in red should be removed. I just can't get a reaction from the function Search. Please explain and sorry for spamming forums today.

JASS:
/*function Trig_Kill_Func001A takes nothing returns nothing
    call RemoveDestructable( GetEnumDestructable() )
endfunction

function Trig_Kill_Actions takes nothing returns nothing
    call EnumDestructablesInRectAll( RectFromCenterSizeBJ(GetRectCenter(gg_rct_Region_001), 64.00, 64.00), function Trig_Kill_Func001A )
endfunction
*/



scope WallBuilder initializer Init 
    globals
        private real array xGrid
        private real array yGrid
        private integer nGrid
        private rect grid
    endglobals
    
    private function AddGridToSearch takes real x, real y returns nothing
        set xGrid[nGrid] = x
        set yGrid[nGrid] = y
        set nGrid = nGrid + 1
    endfunction
    
    private function Search takes nothing returns nothing
        call BJDebugMsg("Found")

        call RemoveDestructable(GetEnumDestructable())
    endfunction
    
    private function Main takes nothing returns boolean
        local integer i = 0
        local unit u = GetFilterUnit()
        local real x0 = GetUnitX(u)
        local real y0 = GetUnitY(u)
        local real x
        local real y
        loop
            set x = x0 + xGrid[i]
            set y = y0 + yGrid[i]
            call MoveRectTo(grid,x,y)
            call EnumDestructablesInRectAll( RectFromCenterSizeBJ(Location(x, y), 128.00, 128.00), function Search )
            //call EnumDestructablesInRect(grid, null, function Search)
            set i = i + 1
            exitwhen i == nGrid
        endloop
        return false 
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        local real k = 128*0.5
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_CONSTRUCT_FINISH, Filter(function Main))
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call AddGridToSearch(0,128)
        call AddGridToSearch(0,-128)
        call AddGridToSearch(128,0)
        call AddGridToSearch(-128,0)
        set grid = Rect(-k,-k,k,k)
   endfunction
endscope
 

Attachments

  • arrghh.png
    arrghh.png
    275.5 KB · Views: 85

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
nGrid is not initialized to a value. All non-array variables (both local and global) must be initialized to a value before being accessed. Accessing an uninitialized non-array variable causes a thread crash at the point of access so all script after it never gets executed.

Does the "boolexpr filter" parameter of the native even work? Many natives have dysfunctional parameters. Specifically make sure that the event response natives work with it, as they might not and return default values instead.

Function main leaks a handle index as well as 4 locations.

The wall corners you want removed do not match the ones it should be removing. It should remove in a '+' shape with exception of the middle (so top, left, down and right).

Maybe instead of this...
JASS:
    call AddGridToSearch(0,128)
    call AddGridToSearch(0,-128)
    call AddGridToSearch(128,0)
    call AddGridToSearch(-128,0)
You meant this...
JASS:
    call AddGridToSearch(0,0)
    call AddGridToSearch(-128,128)
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
nGrid is not initialized to a value. Although JASS should assume it is 0, it is not very good practice to do, especially when performance is not critical such as at map initialization.

Does the "boolexpr filter" parameter of the native even work? Many natives have dysfunctional parameters. Specifically make sure that the event response natives work with it, as they might not and return default values instead.

Function main leaks a handle index as well as 4 locations.

I want to search the 4 grids in the horizontal and vertical plain next to it. It just doesn't work at all. I only used that BJ to see if I could get some reaction out of it.

Even if I take away the boolexpr and add a TriggerAction it wont find anything. ;/
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Change the line...
JASS:
private integer nGrid
to...
JASS:
private integer nGrid = 0

You are probably getting a thread crash when this line is executed.
JASS:
set xGrid[nGrid] = x
This is because the global variable "nGrid" is never initialized. Accessing an uninitialized non-array variable causes a thread crash.

It took me an hour but I eventually found where I posted the proof of this.
 
Status
Not open for further replies.
Top