Search Unity

Need help with AI

Discussion in 'Scripting' started by Mqtt30, Jul 19, 2017.

  1. Mqtt30

    Mqtt30

    Joined:
    Jun 8, 2017
    Posts:
    23
    i got 4 errors like this how i can fix this?
    Cannot return a value from iterators. Use the yield return statement to return a value, or yield break to end the iteration
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    I assume you're trying to do Coroutines. Take a look at how they work. If you need to get values out of a coroutine, another way is to supply a delegate that the coroutine invokes to "pass out" the data. You cannot simply return it.
     
  3. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    Show us an example of some code this is occurring with and we will be able to help.
     
  4. Mqtt30

    Mqtt30

    Joined:
    Jun 8, 2017
    Posts:
    23
    // no target - stop hunting
    if(target == null || (TargetAIComponent && !TargetAIComponent.enabled) && !huntPlayer){
    timeout = 0.0f;
    heardPlayer = false;
    heardTarget = false;
    damaged = false;
    TargetAIComponent = null;
    return false;
    }

    The console says that "return false" is wrong.
    http://imgur.com/a/TOAY6
     
    Last edited: Jul 20, 2017
  5. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    Need to see the function declaration.

    If you want to return true or false the function needs to be: bool FunctionName(myParameters)
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    And please OP, use the code tags properly. Look at the first or second post in this forum for guidance.