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

[Solved] TimerUtilsEx - sending struct to timer doesn't allow dot syntax?

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
I'm creating a little respawn system for a extremely new GUI user so he can setup unit respawns by unit type, respawn time, removal time, current/initial positioning and unit owner through setting GUI variables.

I've setup a struct like this:

JASS:
struct respawnUnit extends array
    unit u
    integer conf
    integer id
    real posX
    real posY
    private static integer instanceCount = 0
    private static thistype recycle = 0
    private thistype recycleNext
    
    method destroy takes nothing returns nothing
        set .u = null
        set recycleNext = recycle
        set recycle = this
    endmethod
    
    static method create takes unit u, integer conf, integer id returns thistype
        local thistype this
        if (recycle == 0) then
            set instanceCount = instanceCount + 1
            set this = instanceCount
        else
            set this = recycle
            set recycle = recycle.recycleNext
        endif
        set .u = u
        set .posX = GetUnitX(u)
        set .posY = GetUnitY(u)
        set .id = id
        set .conf = conf
        return this
    endmethod
endstruct

When I do the following using TimerUtilsEx to attach timer data it tells me I can't use the dot syntax.

Am I missing something?
JASS:
private function respawnUnit takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local respawnUnit u = GetTimerData(t)

    //Can't use dot syntax here

    if udg_CreepRespawnCurrentPosition[u.conf] then
        call CreateUnit(udg_CreepOwner[u.conf], udg_CreepType[u.conf], u.posX, u.posY, CreepFace[u.id])
    else
        call CreateUnit(udg_CreepOwner[u.conf], udg_CreepType[u.conf], CreepPositionX[u.id], CreepPositionY[u.id], CreepFace[u.id])
    endif
    call u.destroy()
    call ReleaseTimer(t)
endfunction

private function removeUnit takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local respawnUnit u = GetTimerData(t)
    local timer respawnTime = NewTimer()

    //haven't tested if I can use dot syntax here

    call RemoveUnit(u.u)
    set u.u = null
    call TimerStart(respawnTime, udg_CreepRespawnTime[u.conf], false, function respawnUnit)
    call SetTimerData(respawnTime, u)
    call ReleaseTimer(t)
endfunction

private function respawnUnitActions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local respawnUnit sendUnit
    local integer id = GetUnitUserData(u)
    local integer i = 1
    local timer deathTime = NewTimer()
    loop
        exitwhen i > udg_lastIndex
        if GetUnitTypeId(u) == udg_CreepType[i] then
            if isIndexed(u, id) then
                set sendUnit = sendUnit.create(u, id, i)
                call TimerStart(deathTime, udg_CreepRemovalTime[i], false, function removeUnit)
                call SetTimerData(deathTime, sendUnit)
            endif
        endif
    endloop
        
    return false
endfunction
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Yeah, I know :/ that's the strange part, these functions are in the right order underneath the struct in the header output...
Yet Jasshelper shows me I can't use the dot syntax.

Maybe it has something to do with http://www.hiveworkshop.com/forums/...ls-280/coding-efficient-vjass-structs-187477/?
Maybe I'm doing something wrong with the struct recycling? It seems right to me.

I'm using jngp 2.0 so maybe it's a jasshelper version problem?
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
JASS:
private function respawnUnit takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local respawnUnit u = GetTimerData(t)
Why does the function has the same name like the struct? Maybe that causes an syntax error.

Edit: Why is it a function at all? Can you declare thistypes outside structs?

oh wow, I didn't even notice that, maybe that's the problem. I'll check it out thank you.

Edit: Why is it a function at all? Can you declare thistypes outside structs?

The function is a timer callback.
You're right though, I could've putted it all inside the struct. But this was a matter of personal prefference for readability.
How do you declare struct instances?


EDIT: yep jasshelper spitted the struct name out as: creepRespawn__respawnUnit which was the same as the function.
Thanks! +rep
 
Status
Not open for further replies.
Top