@Chaoscoder: The problem is that a wait won't let the calling function wait. The calling function will continue to run regardless of the scheduler state of any called function. That means you should not use wait and afterwards a return. When you use a return statement it must be executed in the exactly same frame as the function was called. Hence you cannot wait for return values. Either the value was returned immediately or no value at all will be returned. Example:
Code:
int foo()
{
  wait(1);
  return 1337; // Don't do this! It's wrong!
}
void bar()
{
  int i = 0;
  i = foo(); // Don't do this!
  while (!i) wait(1); // Pointless. The assignment to i has already been done. i won't change eventually.
}



Always learn from history, to be sure you make the same mistakes again...