On Monday, February 23, 2004, at 03:12  pm, Peter Bochan wrote:
> Hi Peter,
> 
> It seems to me that there is some confusion in your code...
> 
> First, you create a new timeOut object every stepFrame. Thankfully, you
> have not appended your object to the actorList (which triggers stepFrame
> events), otherwise your script could create all sorts of weirdnesses!
> 
> Second, it is good practice to do your own garbage collection. I mean
> that if you instantiate an object, it is worthwhile explicitly killing
> that object yourself in order to avoid any memory leaks. Have a look at
> the "forget" command in relation to timeOut objects.
> 
> You might like to try something like:
> 
> -- Parent script "car"
> property name
> property velocity
> 
> on new(me, tName, tVelocity)
>    name = tName
>    velocity = tVelocity
>    return me
> end
> 
> on destroy(me)
>    -- kills the timeOut object if it exists
>    timeout("timer1").forget()
> end
> 
> on showInfo(me)
>    put ("My name is") && name
>    put ("My velocity is") && velocity
> end
> 
> on showInfoInMessageWindow(me)
>    -- you don't have to pass your object ref - it is already "me"
>    timeOut().new("timer1", 2000, #showInfo, me)
> end
> 
> Run the movie
> 
> -- Message Window
> myObject = script("car").new("bmw", 200)
> myObject.showInfoInMessageWindow()
> 
> -- and now to dispose of the object
> myObject.destroy()
> myObject = VOID
> 
> hth, Chris

Hello Christian, thanks a lot for bringing more clarifications.

Yes, you are right, calling the timeOut().new() in stepFrame() will soon end
up in a timeout porridge.

You proposed one more handler:

on destroy(me)
        timeout("timer1").forget()
end

but I've tried to do without it, and it "somewhat" worked. (I don't know if
it's allowed though).

When the movie was running, in the message window I did this:
put the timeOutList
-- [timeOut("timer1")]

when I stopped the movie it looked like this:
put the timeOutList
-- []

that is, as you stated yourself, myObject = VOID did the clean up of the
object, but, as I've figured out, of the timeout object as well. Don't know
if I'm wrong though.

So the ending script (and now simplified a bit) looks like:

-- Frame behavior
on exitFrame(me)
  go(the frame)
end


-- Movie script
on startMovie()
  myObject = script("car").new("bmw", 220)
end

on stopMovie()
  myObject = VOID
end


-- Parent script
property name
property velocity

on new(me, tName, tVelocity)
  name = tName
  velocity = tVelocity
  timeOut().new("timer1", 2000, #showInfo, me)
  return(me)
end

on showInfo(me)
  put ("My name is") && name
  put ("My velocity is") && velocity
end

TIA
peb965




[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email [EMAIL 
PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping 
with programming Lingo.  Thanks!]

Reply via email to