Search Unity

Question I can't figure out with my 'array is filled' routine isn't working

Discussion in 'Scripting' started by davidnibi, Apr 8, 2021.

  1. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    426
    Code (CSharp):
    1.     bool IsArrayEmpty ()
    2.     {
    3.         for (int i = 0; i < pickupHandleComplete.Length; i++)
    4.         {
    5.             if (pickupHandleComplete[i])
    6.             {
    7.                 return true;
    8.                 print ("TRUE");
    9.             }
    10.         }
    11.         return false;
    12.         print ("FALSE");
    13.     }
    I run this with:

    Code (CSharp):
    1. allFree = IsArrayEmpty ();
    When pickupHandleComplete is 'filled', it should return true. But it doesn't seem to process it, and I'm getting

    Code (CSharp):
    1. warning CS0162: Unreachable code detected
    For my print test statements
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Both of your print statements are AFTER a return statement so... not reachable!