• 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] Bug about struct

Status
Not open for further replies.
Level 18
Joined
Sep 14, 2012
Messages
3,413
[SOLVED] Bug about struct

Hi everyone,
I'm here ( again ! ) to ask ( another ! ) question, i'm a begginner in vJASS and in OOP in general.

So here the code :

JASS:
library GlobalLibrary
    globals
        constant string stun_model = "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl"
        constant string slow_model = "Abilities\\Spells\\Human\\slow\\slowtarget.mdl"
        constant string root_model = "Abilities\\Spells\\NightElf\\EntanglingRoots\\EntanglingRootsTarget.mdl"
        timer array T_timer
        effect array T_effect
        integer T_index = 0
    endglobals

    struct debuff
        boolean pause
        real time
        string model
        string attach
        real ms
        unit targ
        
        static method create takes boolean b, real r, string s, string str, real ms, unit u returns debuff
            local debuff d = debuff.allocate()
            set d.pause = b
            set d.time = r
            set d.model = s
            set d.attach = str
            set d.ms = ms
            set d.targ = u
            return d
        endmethod
    endstruct
    
    globals
        debuff array T_debuff
    endglobals
    
    private function InitDebuff takes debuff d returns nothing
        if ( T_index > 3000 ) then
            set T_index = 0
        endif
        set T_effect[T_index] = AddSpecialEffectTarget( d.model, d.targ, d.attach )
        set T_timer[T_index] = CreateTimer()
        set T_debuff[T_index] = d
        set T_index = T_index + 1
    endfunction
    
    function DestroyDebuff takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer index
        local debuff d
        local integer i = 0
        loop
            exitwhen i > 3000
            if ( t == T_timer[i] ) then
                set index = i
                set i = 3000
            endif
            set i = i + 1
        endloop
        set d = T_debuff[index]
        if ( d.pause == true ) then
            call PauseUnit( d.targ, false )
        endif
        call SetUnitMoveSpeed( d.targ, GetUnitMoveSpeed( d.targ ) + d.ms )
        call DestroyEffect( T_effect[index] )
        call DestroyTimer( t )
        call DestroyTimer(  T_timer[index] )
        call d.destroy()
        call T_debuff[index].destroy()
        set t = null
        set T_timer[index] = null
        set T_effect[index] = null
    endfunction
    
    function AddDebuff takes debuff d returns nothing
        if ( T_index > 3000 ) then
            set T_index = 0
        endif
        set T_effect[T_index] = AddSpecialEffectTarget( d.model, d.targ, d.attach )
        set T_timer[T_index] = CreateTimer()
        set T_debuff[T_index] = d
        set T_index = T_index + 1
        call PauseUnit( d.targ, d.pause )
        call SetUnitMoveSpeed( d.targ, GetUnitMoveSpeed( d.targ ) - d.ms )
        call TimerStart( T_timer[T_index], d.time, false, function DestroyDebuff )
    endfunction
    
    function UnitAddStun takes unit u, real time returns nothing
        local debuff d = debuff.create( true, time, stun_model, "overhead", 0, u )
        if ( T_index > 3000 ) then
            set T_index = 0
        endif
        set T_effect[T_index] = AddSpecialEffectTarget( d.model, d.targ, d.attach )
        set T_timer[T_index] = CreateTimer()
        set T_debuff[T_index] = d
        set T_index = T_index + 1
        call PauseUnit( d.targ, true )
        call TimerStart( T_timer[T_index], time, false, function DestroyDebuff )
        call d.destroy()
    endfunction
    
    function UnitAddSlow takes unit u, real time, real ms returns nothing
        local debuff d = debuff.create( false, time, slow_model, "origin", ms, u )
        if ( T_index > 3000 ) then
            set T_index = 0
        endif
        set T_effect[T_index] = AddSpecialEffectTarget( d.model, d.targ, d.attach )
        set T_timer[T_index] = CreateTimer()
        set T_debuff[T_index] = d
        set T_index = T_index + 1
        call SetUnitMoveSpeed( d.targ, GetUnitMoveSpeed( d.targ ) - d.ms )
        call TimerStart( T_timer[T_index], d.time, false, function DestroyDebuff )
        call d.destroy()
    endfunction
    
    function UnitAddRoot takes unit u, real time returns nothing
        local debuff d = debuff.create( false, time, root_model, "origin", GetUnitMoveSpeed( u ) - 1, u )
        if ( T_index > 3000 ) then
            set T_index = 0
        endif
        set T_effect[T_index] = AddSpecialEffectTarget( d.model, d.targ, d.attach )
        set T_timer[T_index] = CreateTimer()
        set T_debuff[T_index] = d
        set T_index = T_index + 1
        call SetUnitMoveSpeed( d.targ, 1 )
        call TimerStart( T_timer[T_index], time, false, function DestroyDebuff )
        call d.destroy()
    endfunction
endlibrary

In one of my spells i'm calling the function like this :

JASS:
UnitAddSlow( f, time, 15 )

So the result is that the effect and the movement speed reduction work but they never disappear.
 
Last edited by a moderator:
Status
Not open for further replies.
Top