Order of code execution
RedRobo
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
i am pretty sure it’s first layers from bottom up, and within layers and actors from top down.
Thanks @bob loblaw much appreciated.
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support