Can you control the order of execution of behaviors?

jamesvhyde

  • Posts: 25
I have an actor with four behaviors, each of which has a handler for collision. Is there a way I can control in what order the four handlers execute? One way to solve this would be to put all the collision code in one behavior, but I'd like to keep the behaviors as independent as possible.

Epic428

  • Posts: 1118
Unfortunately, I do not think it is at all possible to change the order of execution. I could certainly see why it would have its benefits, however, in some cases there is a way to trick the order of execution by using do after blocks. This is more so of a hackish workaround, I know, but it does work.

In terms of your collision response, I doubt it would work. One Idea I have that might be a bit hackish, I believe that the order of execution might be based on certain factors. For example, the order could be based off which behaviors were added to an actor/scene first.

One way to test this would be to put different print statements in the when created section of behaviors, then add the behaviors in a certain order. Do this same thing using a separate actor, but add them in a different order. Verify the order in which the statements were executed to confirm whether it works or doesn't.

Now, if there is somehow an upper level method in the API that can be accessed, such as an array that stores the behaviors and then executes those behaviors based off the order in the array, and you can access the method, then you might be able to use some code to modify the order yourself, again, rather hackish.

Anyway, these are just some ideas that you could run with and see what works and doesn't work. At least until  a way to change the order has been implemented, whatever solution is found, would likely be worthy of a Stencylpedia article so others could take advantage of it.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Joe

  • *
  • Posts: 2478
May I ask what you are trying to accomplish by knowing the order?

jamesvhyde

  • Posts: 25
OK. I was going to try to tell what direction the actor had been moving prior to the collision by checking its x and y speed. Now that I think about it the physics will have already stopped the actor, so this won't work anyway.

I was also trying to change the animation of the actor so it would stop colliding with the first object it collided with. This was preventing the Enemies Health behavior from subtracting on collision. This is actually a behavior on a separate actor. I guess I need to take a different approach.

« Last Edit: July 25, 2011, 07:12:52 pm by jamesvhyde »

jamesvhyde

  • Posts: 25
Thanks, Epic. I had already tested to see what the order was, using the print method you described. It did indeed seem to be the order the behaviors appear in the Actor editor. But there's no way (from the interface) to control what order they appear in, except by putting them in groups.

Joe

  • *
  • Posts: 2478
You can use the collision normal to get more information about the angle of the collision. That might lead you down the right path.