Order of code execution

RedRoboRedRobo Member, PRO Posts: 682

Is there anyone who can give a definitive answer to my simple question as I've heard differing opinions?

Does behaviours/code within actors execute from the top down or from the bottom up?

Many thanks.

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    i am pretty sure it’s first layers from bottom up, and within layers and actors from top down.

  • RedRoboRedRobo Member, PRO Posts: 682

    Thanks @bob loblaw much appreciated.

  • ArmellineArmelline Member, PRO Posts: 5,364

    In actors, code is normally executed from top to bottom. This is not guaranteed, though, and I've encountered many situations where code has executed in another order. To guarantee top to bottom, you have to put it in a timer with run to completion checked.

    As bob says, for layers it's bottom to top.

  • RedRoboRedRobo Member, PRO Posts: 682

    @Armelline said:
    In actors, code is normally executed from top to bottom. This is not guaranteed, though, and I've encountered many situations where code has executed in another order. To guarantee top to bottom, you have to put it in a timer with run to completion checked.

    As bob says, for layers it's bottom to top.

    Thanks @Armelline that's interesting. I normally do use timers but just wondered if I could get an increase in processing speed by removing timers and just ordering things correctly.

  • ArmellineArmelline Member, PRO Posts: 5,364

    @strag said:
    Thanks @Armelline that's interesting. I normally do use timers but just wondered if I could get an increase in processing speed by removing timers and just ordering things correctly.

    Likely yes, you would get an increase. But you'd have to be using a ton of timers right now for it to be noticeably quicker when you removed them.

    The vast majority of the time, code will be executed in order. You only need to use a timer (for this reason) when you're dealing with something that absolutely must happen in a certain order.

    I suspect that you could remove a lot of your timers and it would be fine. But I also suspect you'll see minimal improvement in speed, unless we're talking about a lot of timers.

Sign In or Register to comment.