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

[vJASS] Table & struct variable always null

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I can't figure out what im Doing wrong. I'm trying to fetch a Table based on GetHandleId(unit) but for some reason the struct attributes rect r and integer zoneId is always null when onLeaevZone is executed.



JASS:
library DogSetup initializer Init
 
    globals
        private player neutral = Player(PLAYER_NEUTRAL_AGGRESSIVE)
        private rect array zones
        private group array dogGroup
        private constant integer REGULAR_WOLF = 'n000'
    
        private Table table
 
    endglobals
 
    struct Dog
        integer zoneId
        rect r
        unit u
        timer t
        integer minWander
        integer maxWander
    
        static method create takes integer unitType, integer zoneId, integer min, integer max returns thistype
            local thistype this = .allocate()
            local location p = GetRandomLocInRect(zones[zoneId])
            local real x = GetLocationX(p)
            local real y = GetLocationY(p)
            call RemoveLocation(p)
            set this.r = zones[zoneId]
            set this.u = CreateUnit(neutral, unitType, x, y, bj_UNIT_FACING)
            set table[GetHandleId(this.u)] = this
            call GroupAddUnit(dogGroup[zoneId], this.u)
            set this.zoneId = zoneId
            call BJDebugMsg("zoneId: " + I2S(this.zoneId))
            call this.setWanderInterval(min, max)
        
            return this
        endmethod
    
        method setWanderInterval takes integer min, integer max returns nothing
            set minWander = min
            set maxWander = max
        endmethod
    
        method randomMove takes nothing returns nothing
            local location p = GetRandomLocInRect(zones[this.zoneId])
            call BJDebugMsg("Zone: " + I2S(this.zoneId))
            call IssuePointOrderLocBJ(this.u, "move", p)
            call PingMinimapLocForForceEx(GetPlayersAll(), p, 1, bj_MINIMAPPINGSTYLE_SIMPLE, 100, 100, 100)
            call RemoveLocation(p)
            set p = null
            call BJDebugMsg("Random Move: " + I2S(this.zoneId))
        endmethod
    
        private static method doWander takes nothing returns nothing
    
        endmethod
    endstruct
 
    function spawnDogs takes nothing returns nothing
    
    endfunction
 
    private function OnLeaveZone takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local Dog dog
        if (GetOwningPlayer(u) == neutral) then
            set dog = Table[GetHandleId(u)]
            if (dog != 0) then
                call dog.randomMove()
            endif
        endif
        set u = null
        return false
    endfunction
 
    private function Init takes nothing returns nothing
        local integer i = 0
        local integer j
        local real h
        local real w
        local real factor
        local integer numOfWolves
        local trigger tLeaveZone = CreateTrigger()
        local Dog dog
        set zones[0] = gg_rct_Lane00
        set zones[1] = gg_rct_Lane01
        set zones[2] = gg_rct_Lane02
        set zones[3] = gg_rct_Lane03
        set zones[4] = gg_rct_Lane04
        set zones[5] = gg_rct_Lane05
        set zones[6] = gg_rct_Lane06
        set zones[7] = gg_rct_Lane07
        set zones[8] = gg_rct_Lane08
        set zones[9] = gg_rct_Lane09
        set zones[10] = gg_rct_Lane10
        set zones[11] = gg_rct_Lane11
        set zones[12] = gg_rct_Lane12
        set zones[13] = gg_rct_Lane13
        set zones[14] = gg_rct_Lane14
        set zones[15] = gg_rct_Lane15
        set zones[16] = gg_rct_Lane16
        set table = Table.create()
        call TriggerAddCondition(tLeaveZone, Condition(function OnLeaveZone))
        loop
            exitwhen zones[I] == null
            set dogGroup[I] = CreateGroup()
            call TriggerRegisterLeaveRectSimple(tLeaveZone, zones[I])
            set h = GetRectHeightBJ(zones[I])
            set w = GetRectWidthBJ(zones[I])
            set factor = 344064.00
            set numOfWolves = R2I(w*h/factor)
            call BJDebugMsg("Wolves: " + I2S(numOfWolves))
            set j = 0
            loop
                exitwhen j == numOfWolves
                call Dog.create(REGULAR_WOLF, i, 3, 9)
                set j = j + 1
            endloop
            set i = i + 1
        endloop
    endfunction
endlibrary
 
Last edited:
The _udg variables are not initialisized, yet. Maybe use a 0-seconds timer.

JASS:
    exitwhen zones[I] == null
    set dogGroup[I] = CreateGroup()
    call TriggerRegisterLeaveRectSimple(tLeaveZone, zones[I])
    set h = GetRectHeightBJ(zones[I])
    set w = GetRectWidthBJ(zones[I])
why big i, "I" ?

I would find it some easier to if the rect is given as parameter to the constructor, instead of giving the indix only.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
The _udg variables are not initialisized, yet. Maybe use a 0-seconds timer.

JASS:
    exitwhen zones[I] == null
    set dogGroup[I] = CreateGroup()
    call TriggerRegisterLeaveRectSimple(tLeaveZone, zones[I])
    set h = GetRectHeightBJ(zones[I])
    set w = GetRectWidthBJ(zones[I])
why big i, "I" ?

I would find it some easier to if the rect is given as parameter to the constructor, instead of giving the indix only.

The big I is a bug that happend when copying from notepad, idk.^^

Would it be solved if i put all the rects used inside a struct init? Like below or would I still ned a timer on that Init?

JASS:
library Zones
    struct Zone
        private static rect array checkPoint
        private static rect array lane
        private static rect finish
        private static rect start
    
        static method randomStartX takes nothing returns real
        
        endmethod
    
        static method randomStartY takes nothing returns real
    
        endmethod
    
        static method onInit takes nothing returns nothing
            set Zone.checkPoint[0] = gg_rct_Corner00
            set Zone.checkPoint[1] = gg_rct_Corner01
            set Zone.checkPoint[2] = gg_rct_Corner02
            set Zone.checkPoint[3] = gg_rct_Corner03
            set Zone.checkPoint[4] = gg_rct_Corner04
            set Zone.checkPoint[5] = gg_rct_Corner05
            set Zone.checkPoint[6] = gg_rct_Corner06
            set Zone.checkPoint[7] = gg_rct_Corner07
            set Zone.checkPoint[8] = gg_rct_Corner08
            set Zone.checkPoint[9] = gg_rct_Corner09
            set Zone.checkPoint[10] = gg_rct_Corner10
            set Zone.checkPoint[11] = gg_rct_Corner11
            set Zone.checkPoint[12] = gg_rct_Corner12
            set Zone.lane[0] = gg_rct_Lane00
            set Zone.lane[1] = gg_rct_Lane01
            set Zone.lane[2] = gg_rct_Lane02
            set Zone.lane[3] = gg_rct_Lane03
            set Zone.lane[4] = gg_rct_Lane04
            set Zone.lane[5] = gg_rct_Lane05
            set Zone.lane[6] = gg_rct_Lane06
            set Zone.lane[7] = gg_rct_Lane07
            set Zone.lane[8] = gg_rct_Lane08
            set Zone.lane[9] = gg_rct_Lane09
            set Zone.lane[10] = gg_rct_Lane10
            set Zone.lane[11] = gg_rct_Lane11
            set Zone.lane[12] = gg_rct_Lane12
            set Zone.lane[13] = gg_rct_Lane13
            set Zone.lane[14] = gg_rct_Lane14
            set Zone.lane[15] = gg_rct_Lane15
            set Zone.lane[15] = gg_rct_Lane16
            set Zone.finish = gg_rct_Finish
            set Zone.start = gg_rct_StartZone
        endmethod
    
    endstruct
 
endlibrary

*Edit

I just realized, it cant be because the rects have not been initialized as the index and rects are used properly onCreate. It's after when an event occurs that the rect is null (or the index).
 
Last edited:
Status
Not open for further replies.
Top