HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Quick Struct Question

05-10-2008, 01:33 AM#1
Joker
How do you destroy/remove stuff that you are passing through a struct? would this work?

Collapse JASS:
struct a
    group g

    static method create takes group g returns a
        local a dat = a.allocate()
        set dat.g = g
        return dat
    endmethod
endstruct

function qwe takes nothing returns boolean
    local a dat = TT_GetData() //Cohadar's
    //stuff
    call DestroyGroup(dat.g)
    call dat.destroy()
    return true
endfunction

function asd takes nothing returns nothing
    local group g = CreateGroup()
    call TT_Start(function qwe, a.create(g)) //Cohadar's
    set g = null
endfunction
05-10-2008, 01:41 AM#2
moyack
Create an onDestroy method which will do the cleaning of the components of your struct.

In your example:
Collapse JASS:
struct a
    group g

    static method create takes group g returns a
        local a dat = a.allocate()
        set dat.g = g
        return dat
    endmethod

    method onDestroy takes nothing returns nothing
        call GroupClear(.g)
    endmethod
endstruct

...

function qwe takes nothing returns boolean
    local a dat = TT_GetData() //Cohadar's
    //stuff
    //call DestroyGroup(dat.g) <= not needed anymore, dat.destroy() will do now the stuff for you :)
    call dat.destroy()
    return true
endfunction
05-10-2008, 01:42 AM#3
Vexorian
can't you test it yourself?

A good way is to use onDestroy, but that one works as well.
05-10-2008, 03:56 AM#4
Pyrogasm
In case you're confused, Moyack means to say:
Collapse JASS:
method onDestroy takes nothing returns nothing
    call DestroyGroup(.g)
endmethod