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

[vJASS] Table not working properly??

Status
Not open for further replies.
Level 10
Joined
May 27, 2009
Messages
495
I'm making some sort of revive system
apparently, when it is time for them to revive, the registered data on Table doesn't exist anymore??
well that happens on static method ch takes nothing returns nothing method

Sorry for the messed up code, it's currently in "debug mode" code lol

JASS:
library HeroReviveSystem uses Table, RegisterPlayerUnitEvent
    globals
        private constant integer INTERVAL = 1
        private Table tb
    endglobals
    
    //! textmacro HeroReviveSystem_CalculateTime
        set dur = /*
        */10
    //! endtextmacro
    
    private struct HeroRevive
        private static integer array ic
        private static integer c
        private static timer t
        
        static method ct takes unit hero returns real
            local integer dur = 0
            //! runtextmacro HeroReviveSystem_CalculateTime()
            return I2R(dur)
        endmethod
        
        static method ch takes nothing returns nothing
            local integer i = 0
            local integer h
            loop
                exitwhen i >= c
                set h = ic[i]
                if tb.has(ic[i]) then
                    set tb.real[h] = tb.real[h] - INTERVAL
                    if tb.leaderboard[h] != null then
                        call LeaderboardSetLabel(tb.leaderboard[h],"Respawn in " + I2S(R2I(tb.real[h])) + " seconds")
                    elseif tb.real[h] > 1 then //leaderboard nulled? wtf happened
                        set tb.leaderboard[h] = CreateLeaderboard()
                        call PlayerSetLeaderboard(tb.player[h],tb.leaderboard[h])
                        call LeaderboardSetLabel(tb.leaderboard[h],"Respawn in " + I2S(R2I(tb.real[h])) + " seconds")
                        call LeaderboardDisplay(tb.leaderboard[h],true)
                    else
                        set tb.real[h] = 0
                    endif
                    if tb.real[h] <= 0 then
                        set tb.real[h] = 0
                        call BJDebugMsg(I2S(ic[i]) + "/" + I2S(c) + "/" + I2S(i))
                        call BJDebugMsg("u: " + GetUnitName(tb.unit[h]))
                        call BJDebugMsg("x: " + R2S(GetLocationX(tb.location[h])) + " y:" + R2S(GetLocationY(tb.location[h])))
                        if ReviveHeroLoc(tb.unit[h],tb.location[h],true) then
                            call BJDebugMsg("start revive")
                        endif
                        call LeaderboardDisplay(tb.leaderboard[h],false)
                        
                        set c = c - 1
                        set ic[i] = ic[c]
                        
                        set i = i - 1
                    endif
                endif
                set i = i + 1
            endloop
            if c == 0 then
                call PauseTimer(t)
            endif
        endmethod
        
        static method d takes nothing returns boolean
            local unit u = GetTriggerUnit()
            local player p = GetOwningPlayer(u)
            local integer h = GetPlayerId(p)
            if tb.has(h) and tb[h] == GetHandleId(u) then
                set tb.unit[h] = u
                call BJDebugMsg("u: " + GetUnitName(tb.unit[h]))
                set tb.real[h] = thistype.ct(tb.unit[h])
                if tb.leaderboard[h] == null then
                    set tb.leaderboard[h] = CreateLeaderboard()
                endif
                call PlayerSetLeaderboard(p,tb.leaderboard[h])
                call LeaderboardSetLabel(tb.leaderboard[h],"Respawn in " + I2S(R2I(tb.real[h])) + " seconds")
                call LeaderboardDisplay(tb.leaderboard[h],true)
                if c == 0 then
                    call TimerStart(t,I2R(INTERVAL),true,function thistype.ch)
                endif
                set ic[c] = h
                set c = c + 1
            endif
            set p = null
            set u = null
            return false 
        endmethod
        
        static method r takes unit u, real x, real y returns nothing
            local player p = GetOwningPlayer(u)
            local integer h = GetPlayerId(p)
            if not tb.has(h) then
                set tb[h] = GetHandleId(u)
                set tb.player[h] = p
                set tb.location[h] = Location(x,y)
                call BJDebugMsg("x: " + R2S(GetLocationX(tb.location[h])) + " y:" + R2S(GetLocationY(tb.location[h])))
            debug else
            debug call BJDebugMsg("[HeroReviveSystem]: Player " + I2S(h) + " is already registered!")
            endif
            set p = null
        endmethod
        
        static method u takes unit u, real x, real y returns nothing
            local player p = GetOwningPlayer(u)
            local integer h = GetPlayerId(p)
            if tb.has(h) then
                call RemoveLocation(tb.location[h])
                set tb.location[h] = Location(x,y)
            debug else
            debug call BJDebugMsg("[HeroReviveSystem]: Cannot update player " + I2S(h) + ": Player not registered!")
            endif
            set p = null
        endmethod
        
        static method onInit takes nothing returns nothing
            set tb = Table.create()
            set t = CreateTimer()
            set c = 0
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH,function thistype.d)
        endmethod
    endstruct
    
    function RegisterHeroOnDeath takes unit h, real x, real y returns nothing
        call HeroRevive.r(h,x,y)
    endfunction
    
    function UpdateHeroReviveLocation takes unit h, real x, real y returns nothing
        call HeroRevive.u(h,x,y)
    endfunction
endlibrary
 
Status
Not open for further replies.
Top