Function() Order In A Script

Post » Thu Sep 26, 2013 5:47 am

Hey guys I wasn't sure how to put this in the title of the post. Basically see example code below.

Function SomeFunction()	myFunction01()	myFunction02()EndFunctionFunction myFunction01()	;code hereEndFunctionFunction myFunction 02()	;code hereEndFunction
In the above script would myFunction01() and myFunction02() functions be completed one after the other before SomeFunction() finishes? So if I'm relying on variables from 01 and 02 to be found to use in SomeFunction(), that would be possible?

Or would myFunction02() fire before myFunction01() finishes?
User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Wed Sep 25, 2013 8:00 pm

myFunction01() - called first

myFunction02() - called second

User avatar
Gavin Roberts
 
Posts: 3335
Joined: Fri Jun 08, 2007 8:14 pm

Post » Wed Sep 25, 2013 9:04 pm

Whenever you call a function from another function or event, the first (calling) function will pause until the function called returns. So in other words, function one will complete all of its code entirely, and if it has a return value, it will be returned to SomeFunction()--and then, only after that, will function two be called.

The one exception to this rule is when you register for something--using registerForSingleUpdate, for instance--the function will register for the update but then immediately keep processing. (This is also why it is often a good idea to use registerForSingleUpdate() in an onInit() event, instead of doing a lot of stuff in the onInit itself, or calling functions that do a lot of stuff from the onInit() -- by registering for an update, you allow the onInit() to finish, and thus the script to finish setting itself up faster, so that it can interact with other scripts freely)

User avatar
Albert Wesker
 
Posts: 3499
Joined: Fri May 11, 2007 11:17 pm

Post » Thu Sep 26, 2013 3:00 am

Good to know :) i suppose that's good if you create your own bool functions for conditioning.
User avatar
Angela Woods
 
Posts: 3336
Joined: Fri Feb 09, 2007 2:15 pm


Return to V - Skyrim