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

[JASS] How to clean ARRAYS

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
I have a loop with an array, and I'm wondering if I need to null the values at the end of each loop or just at the end of the function.

JASS:
loop
exitwhen a>speed
        loop
        exitwhen b>speed
            set q = GetHandleUnit(z,"c"+I2S(a)+"r"+I2S(b))
            set xtraU = GetHandleUnit(z,"c"+I2S(a+1)+"r"+I2S(b))
            set xtraB[1] = GetHandleBoolean(xtraU[1],"o")
            set xtraU = GetHandleUnit(z,"c"+I2S(a)+"r"+I2S(b+1))
            set xtraB[2] = GetHandleBoolean(xtraU[2],"o")
            set xtraU = GetHandleUnit(z,"c"+I2S(a+1)+"r"+I2S(b+1))
            set xtraB[3] = GetHandleBoolean(xtraU[3],"o")
            set xtraB[4] = GetHandleBoolean(q,"o")
            if xtraB[1] == true and xtraB[2] == true and xtraB[3] == true and xtraB[4] == true then
            call SetUnitOwner(q, tp, true)
            endif
            set b = b+1
        endloop
    set b = speed*-1
    set a = a+1
endloop

Don't worry about whether it's fast or not lol I know what I'm doing :p
 
Level 14
Joined
Jan 15, 2007
Messages
349
You have just to clean the unit handle. It should look like this:

JASS:
loop
exitwhen a>speed
        loop
        exitwhen b>speed
            set q = GetHandleUnit(z,"c"+I2S(a)+"r"+I2S(b))
            set xtraU = GetHandleUnit(z,"c"+I2S(a+1)+"r"+I2S(b))
            set xtraB[1] = GetHandleBoolean(xtraU[1],"o")
            set xtraU = GetHandleUnit(z,"c"+I2S(a)+"r"+I2S(b+1))
            set xtraB[2] = GetHandleBoolean(xtraU[2],"o")
            set xtraU = GetHandleUnit(z,"c"+I2S(a+1)+"r"+I2S(b+1))
            set xtraB[3] = GetHandleBoolean(xtraU[3],"o")
            set xtraB[4] = GetHandleBoolean(q,"o")
            if xtraB[1] and xtraB[2] and xtraB[3] and xtraB[4] then
              call SetUnitOwner(q, tp, true)
            endif
            set b = b+1
        endloop
    set b = speed*-1
    set a = a+1
endloop
set xtraU=null
set q=null

There is no need to null non handles like boolean, strings, integer or reals.
 
Status
Not open for further replies.
Top