2 Replies Latest reply on May 5, 2006 12:33 PM by PeterDeMan

    Parent scripts

    Vincent_is_Schattig Level 1
      Good day,

      I want to be an object delete itself.

      At this time the creation happens a following:
      -------
      myObject = script("myScript").new()
      on new me
      return me
      end
      -------

      Now I want the object to delete itself like this:
      ---------
      on forget me
      myObject = void
      end
      ---------
      This does not work because 'myObject' is no reference to the script object.
      How can I achieve this?

      Thank you
        • 1. Re: Parent scripts
          Lukewig Level 1
          Hi,

          An object is deleted when there are no persistent references to it. So, if 'myObject' contains the only reference to the object, then your code should work - assuming you are assigning a reference to myObject and myObject is a global variable or property (it is hard to tell from the code you have posted what 'myObject' is. Assuming the line

          myObject = script("myScript").new()

          is in a different script to the script containing the script for the object, then you will need to make myObject a global and declare it as a global in both scripts.

          A better strategy, I think, is rather than having the object delete itself by voiding a global variable- it requests an object (or script) that contains the persistent reference to delete the reference. In other words, the role 'forget' method (or 'cleanUp' or 'destroy' method) is to tidy up and delete references to other objects - not void variables containing the current object.

          -- Luke
          • 2. Re: Parent scripts
            PeterDeMan Level 1
            hi,

            if i understand correctly it goes a little something like this.

            to make:
            global myObject
            myObject = script("myScript").new()

            to delete:
            global myObject
            myObject = void

            greetingz,
            Peter de Man