Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Interrupting an action  (Read 4183 times)

0 Members and 1 Guest are viewing this topic.

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Interrupting an action
« on: May 30, 2006, 11:46:41 AM »

Hi

Has anyone got a nice way to override an action by another action ? Most of my code for interactive scene objects look like this:

Code: [Select]
on "Take"
{
actor.GoToObject(this);
actor.PlayAnimation("pick_up");
actor.Talk("blah blah");
}

but with that code, if the user clicks on anything while the actor is moving it doesn't stop the current action, it only cancels the movement and the animation is played where the actor is standing when the user clicks.

Enclosing this code between
Code: [Select]
Game.Interactive = false;
[...]
Game.Interactive = true;
won't work either because I want the user to be able to override the action while the actor is moving.

My first idea is to use a global variable that tells the first script that the order was overriden but since script are executed in parallel I can't tell which script will be executed first and receive the order to stop so it's a bit risky, not to mention ugly.

I'm sure there's a simple and elegant solution to do that. Any ideas ?

Thanks,
  Olivier
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Interrupting an action
« Reply #1 on: May 30, 2006, 12:10:24 PM »

Quote
but with that code, if the user clicks on anything while the actor is moving it doesn't stop the current action, it only cancels the movement and the animation is played where the actor is standing when the user clicks.
Are sure about this? Some methods are performed in exclusive mode, which means if the actor is waiting for some method to finish and you call an exclusive method, the entire code block of the original action is cancelled. In your case, if the actor is peforming GoToObject() and you call GoToObject() again from elsewhere, the original event handler should get cancelled, completely. Same for GoTo(), Talk() and TurnTo().

Apparently PlayAnim() is not an exclusive method, I don't remember why.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Interrupting an action
« Reply #2 on: May 30, 2006, 12:14:05 PM »

Hi, my name is adonf and I reply to my own posts ;)

I'm kinda confused by the way the current action gets overriden by a new action in WME. See, my actual code was something like that:

in the actor's script:
Code: [Select]
method CustomGoToObject(node)
{
this.GoToObject(node);
}
(yeah that's stupid but I was originally planning to do a lot of other things in this method)

and in the scene object's file i had:
Code: [Select]
on "Take"
{
actor.CustomGoToObject(this);
actor.PlayAnimation("pick_up");
actor.Talk("blah blah");
}

This code behaves as I said earlier. But if I take out the call to GoToObject from the actor's method and put it in the event handling function then the action is interrupted like I want it to be: if I select "look at" on this object the actor starts moving towards it, then if I select any action on another object the actor gives up the current action and starts the new action.

So it seems to me that when an event is triggered it will kill the current event but only in the deepest call in the callstack. Is this right ? Is this intended behaviour ? Am I making any sense ?

Logged
I am the Milkman. My milk is good.

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Interrupting an action
« Reply #3 on: May 30, 2006, 12:19:46 PM »

Quote
the original event handler should get cancelled, completely.

I just got that after replying to myself.

Are you sure it's the whole handler that gets cancelled, and not just the function that called the function in exclusive mode ?
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Interrupting an action
« Reply #4 on: May 30, 2006, 12:27:48 PM »

Well, it cancels the script (handler, method) which executed the original action, in your case only the custom method is cancelled. That's by design, I'm afraid...
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Interrupting an action
« Reply #5 on: May 30, 2006, 01:54:54 PM »

Ok, I'll just remove all the calls to "CustomGoToObject", but if I do that then sometimes the actor makes a whole turn on itself when I order it to go to an object it's already at.

Actually that's why I wrote CustomGoToObject in the first place, so that I could compare the current position with the destination and only call GoToObject if the actor was not alreay where I wanted it to go. I didn't have to compare the positions since putting the call in a separate function stopped the actor from turning on itself.

Do you know what is going on ?
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Interrupting an action
« Reply #6 on: May 30, 2006, 02:33:24 PM »

Most likely there some 1 pixel difference, so the actor turns to that direction, moves by one pixel, and turns back :(
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Interrupting an action
« Reply #7 on: May 30, 2006, 02:52:55 PM »

Yeah you're probably right. I moved the scene elements around a bit since I had this problem and the problem is gone.

Ok, thanks for the explanations.
Logged
I am the Milkman. My milk is good.
 

Page created in 0.039 seconds with 20 queries.