Sequence of functions

function printCheckArray(){
	printArray();
	checkMatches();	
}

In a situation where one is calling a sequence of functions, sometimes they seem to execute faster than one would like. Almost as if they are being called at the same time.

Is it correct in thinking that the way that code should run would be to first call the printArray() function, then once the printArray() function has completely ran through its code the checkMatches() function would be called?

In this case would a yield WaitForSeconds() be appropriate to provide a slight delay between the function calls? (In order to make them not appear to be executing simultaneously).

Thanks for any help!

Code is processed in linear order.

This means that function one is done by the time function two is called.

The exception to this is when you provide a function with a yield statement(which can be incredibly confusing due to UnityScript’s love for allowing you to hide important information).

A function with a yield in it is a Coroutine.

Coroutines are processed at the end of the current frame, and then with each successive frame after the yield.

This means that if your first function contains a yield, it can be processed after the second one.

Thank you, I really appreciate your insight. I had a suspicion that all of my calls to yield were causing some sort of an issue. I will admit the documentation left me a little confused about the nature of coroutines.

Coroutines are essentially functions that can stop halfway and wait a frame.

Each frame works like this:

Update()
CoroutineUpdate() (This may not be here but it’s close)
LateUpdate()
PreRender()
Render()

And they loop one after the other. So everything within your update gets called in straight order, with the exception of coroutines.

What calling a coroutine function does is tell the CoroutineUpdate to call that function. So it’s not called right away but marked to be called before the frame ends. Yield in a coroutine means Stop this function and Continue the Update Cycle. So it does one full loop before continuing. Using things like WaitForSeconds just tells it to continue yielding to the update loop until x seconds has amassed. But, you can still be sure that everything called between yields gets called in order, and nothing else is processed until it’s done.