Morelli Posted April 21, 2008 Share Posted April 21, 2008 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) Link to comment
norby89 Posted April 21, 2008 Share Posted April 21, 2008 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 Link to comment
Stevvo Posted April 21, 2008 Share Posted April 21, 2008 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. Link to comment
tma Posted April 22, 2008 Share Posted April 22, 2008 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). Link to comment
darkdreamingdan Posted April 27, 2008 Share Posted April 27, 2008 This is normal. Destroying an element doesnt make a pointer to it non-existant. You have to bear in mind you're not destroying the variable. use isElement as norby said. Link to comment
Phat Looser Posted May 1, 2008 Share Posted May 1, 2008 Or just set the variable to nil, since it should be nil when its pointing nowhere. Thats the easiest way of doing "it". Link to comment
Recommended Posts