• 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] Real array expecting size?

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
Hey, I was working on this spell for my map however I've come down to an "Expected [size]" error. But that's impossible for me because I don't know how large the array will get and this is the only one doing this. Any ideas?

JASS:
library ArcDrain initializer init
    globals
        private constant integer SPELL_ID  = 'ArcD'
        private constant integer BUFF_ID   = 'ArcB'
        private constant real MSPEED       = .35
        private constant real TIMERTIME    = 4.
        private real array TIMEOUT
        private boolean array DEALLOCATEME
        private real TURNOVER              = .25
        private timer array TIMER
        private unit array CASTER 
        private unit array TARGET
        private real array DRAIN
        private integer array rn
        private integer ic
    endglobals
    
  struct ArcDrain extends array
        private static method allocate takes nothing returns thistype
            local thistype this = rn[0]
            if this == 0 then
                set ic = ic + 1
                call thistype.spell()
                return ic
            endif
            set rn[0] = rn[this]
            return this
        endmethod
        
        private static method deallocate takes nothing returns nothing
            set CASTER[this] = null
            set TARGET[this] = null
            set TIMER[this] = null
            set rn[this] = rn[0]
            set rn[0] = this
        endmethod
        
        private static method drainer takes nothing returns nothing
            if TIMEOUT[this] <= 0 then
                call DestroyTimer(TIMER[this])
                set DEALLOCATEME[this] = true
            endif
            call SetUnitState(TARGET[this], UNIT_STATE_MANA, (UNIT_STATE_MANA - DRAIN[this]))
            call SetUnitState(CASTER[this], UNIT_STATE_MANA, (UNIT_STATE_MANA + R2I(DRAIN[this] * TURNOVER)))
            set TIMEOUT[this] = TIMEOUT[this] - 1
            if DEALLOCATEME[this] then
                set DEALLOCATEME[this] = false
                call thistype.deallocate()
            endif
        endmethod
        
        private static method spell takes nothing returns nothing
            set CASTER[this] = GetSpellAbilityUnit()
            set TARGET[this] = GetSpellTargetUnit()
            set DRAIN[this] = ((GetUnitAbilityLevel(CASTER[this], SPELL_ID)*20)+50)
            if not TARGET[this] == UNIT_TYPE_DEAD and not TARGET[this] == (IsUnitAlly(TARGET[this], Player(GetPlayerId(GetOwningPlayer(CASTER[this]))))) then
                call UnitAddAbility(TARGET[this], BUFF_ID)
                set TIMER[this] = CreateTimer()
                set TIMEOUT[this] = TIMERTIME
                call TimerStart(TIMER[this], 1., true, function thistype.drainer)
            else
                call thistype.deallocate()
            endif
        endmethod
        
        static method cast takes nothing returns nothing
            if GetSpellAbilityId() == SPELL_ID then
                call thistype.spell()
                return
            endif
        endmethod
    endstruct
        
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_SPELL_CAST, function ArcDrain.cast)
    endmethod
endlibrary

EDIT: Please ignore this... I feel so stupid for forgetting I set it to a default value. I am sorry xD. My bad.
 
Last edited:
Status
Not open for further replies.
Top