Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: creatorbri on February 13, 2004, 05:23:54 AM

Title: Attached method executing in parallel?
Post by: creatorbri on February 13, 2004, 05:23:54 AM
Here's my left-click (Interact) handler for a locked chest object:

Code: [Select]
on "Interact"
{
  actor.GoToObject(self);
 
  // Notebook: Found a very old chest.
  actor.Say ("It's locked!");
}

Obviously the actor should walk to the chest, and then say his line. But sometimes, he skips the GoToObject entirely and just says "It's locked." It works correctly with every other click... the first click always skips, the second click waits for the GoToObject, the third skips, etc.

I tried replacing the line 3 call to my custom GoToObject method with the standard GoTo, and it worked fine.

Here's the GoToObject method:

Code: [Select]
method GoToObject (theObj)
{
  this.GoTo (theObj.standX, theObj.standY);
  this.TurnTo (theObj.Direction);
  if (actor.X == theObj.standX && actor.Y == theObj.standY)
    return true;
  else
    return false;
}
Any ideas what's going on?
Title: Re:Attached method executing in parallel?
Post by: Mnemonic on February 13, 2004, 08:44:55 AM
Well, it may be a little controversial, but it's by design. Every method call starts a new "thread". So does your GoToObject. The actor is walking, but when you click again, you're telling him to do something else. Actor's walking thread is terminated and the old chest script continues. You could check the return value of the GoToObject method. If it's null, the thread has been interrupted.