Jump to content

destroyElement isn't *really* destroyed


Morelli

Recommended Posts

Posted

I found out this while testing GUIs. When an element is destroyed with the function destroyElement, the script still recognises it to exist, even though the visual representation of it (whatever it may be), ceases to exist. A sample code illustrating this can be found below.

function test( button, state, sx, sy, x, y, z, elem, gui ) 
    Grid = guiCreateGridList ( 0.5, 0.5, 0.3, 0.2, true ) 
    destroyElement( Grid ) 
    if ( Grid ) then 
        outputChatBox( "Yes") 
    else 
        outputChatBox( "No") 
    end 
end 
  
addCommandHandler( "o", test) 

Posted

that's normal, try isElement ( Grid ) and you'll see it returns false

when you destroy an element remember to 'nil' the variable it was associated to :)

Posted

Yo, after the destroyElement, add:

 grid = nil 

Problem solved, it seems with destroyElement, only the element itself is destroyed, not the variable the element was in.

Posted

This is normal in any language - see malloc/free in C. The "value" returned from malloc is a pointer (reference) to the memory block. The same thing happens with MTA elements - variables point to the type data but aren't the type themselves (references).

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...