Search Unity

Overloading Coroutines

Discussion in 'Scripting' started by madcalf, May 6, 2006.

  1. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    Can coroutines be overloaded?

    I'm trying to do something like this:
    Code (csharp):
    1. function Fade() {
    2.    // statements...
    3.    // yield ...
    4. }
    5.  
    6. function Fade(duration:float) {
    7.    // statements
    8.    // yield ...
    9. }
    10.  
    But when in Start() I call:
    Code (csharp):
    1.  yield StartCoroutine("Fade", 10);
    2.  
    It seems be calling the first Fade() and ignores the argument.

    So then I tried switching the order of the coroutines to:
    Code (csharp):
    1. function Fade(duration:float) {
    2.    // statements
    3.    // yield ...
    4. }
    5.  
    6. function Fade() {
    7.    // statements...
    8.    // yield ...
    9. }
    Now
    Code (csharp):
    1. yield StartCoroutine("Fade", 10);
    works just fine. But when calling it without an argument:
    Code (csharp):
    1. yield StartCoroutine("Fade");
    I get the following error: "Failed to call the function Fade of Class GuiController. Calling function Fade with no parameters but the function requires 1."

    An earlier version I did with regular functions worked fine this way. So i'm guessing that it's something about the coroutines that is the problem? If that's true, any ideas on another way to have multiple versions of a coroutine that take different arguments?
    Thanks!
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    At the moment you can't overload them.
    Can't you just make the coroutine use another function name?
     
  3. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    yeah, i'll do that. I just wanted to make sure that the coroutine overloading wasn't an option. I thought I was just not doing it right...

    btw, coroutines rock!! Now that i'm getting the hang of them, I wish they had them in ActionScript!

    cheers!
    d