GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Order of code execution

stragstrag Posts: 543Member, PRO

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 Posts: 335Member, PRO

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

  • stragstrag Posts: 543Member, PRO

    Thanks @bob loblaw much appreciated.

  • ArmellineArmelline Posts: 4,751Member, PRO

    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.

  • stragstrag Posts: 543Member, PRO

    @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 Posts: 4,751Member, PRO

    @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.